mirror of
https://gitea.wildfiregames.com/0ad/0ad
synced 2026-06-16 05:13:58 -07:00
Remove glooxwrapper
This wrapper was meant to support multiple C++ ABIs with a single pre-built gloox library wrap as a C library. A new ABI change was rejected a few years back, so this will probably take a while for it to be on the table again. With the bug tracker and mailing list currently unavailable and known TLS issues we might have replaced gloox by then anyway. Supporting multiple ABIs with the current setup isn't an issue either and is already done for 32bit vs 64bit ABI on Windows. Therefore use gloox types directly in lobby code instead of wrapper types and delete the wrapper and build-integration. Migrate to override where applicable, as it helped avoid subtle differences in signatures and finding missing inheritance of LogHandler. Finally use version check instead of os check to work around Windows using the 1.1 development branch instead of releases. Fixes: #7198 Signed-off-by: Ralph Sennhauser <ralph.sennhauser@gmail.com>
This commit is contained in:
parent
087f62d062
commit
0a455fbe2d
13 changed files with 398 additions and 1994 deletions
|
|
@ -377,6 +377,7 @@ extern_lib_defs = {
|
|||
compile_settings = function()
|
||||
if os.istarget("windows") then
|
||||
add_default_include_paths("gloox")
|
||||
defines { "GLOOX_IMPORTS" }
|
||||
else
|
||||
pkgconfig.add_includes("gloox")
|
||||
end
|
||||
|
|
|
|||
|
|
@ -26,8 +26,6 @@ newoption { trigger = "macosx-version-min", description = "Set minimum required
|
|||
newoption { trigger = "sysroot", description = "Set compiler system root path, used for building against a non-system SDK. For example /usr/local becomes SYSROOT/user/local" }
|
||||
|
||||
-- Windows specific options
|
||||
newoption { trigger = "build-shared-glooxwrapper", description = "Rebuild glooxwrapper DLL for Windows. Requires the same compiler version that gloox was built with" }
|
||||
newoption { trigger = "use-shared-glooxwrapper", description = "Use prebuilt glooxwrapper DLL for Windows" }
|
||||
newoption { trigger = "large-address-aware", description = "Make the executable large address aware. Do not use for development, in order to spot memory issues easily" }
|
||||
|
||||
-- Install options
|
||||
|
|
@ -691,25 +689,6 @@ function setup_all_libs ()
|
|||
"fmt",
|
||||
}
|
||||
setup_static_lib_project("lobby", source_dirs, extern_libs, {})
|
||||
|
||||
if _OPTIONS["use-shared-glooxwrapper"] and not _OPTIONS["build-shared-glooxwrapper"] then
|
||||
table.insert(static_lib_names_debug, "glooxwrapper_dbg")
|
||||
table.insert(static_lib_names_release, "glooxwrapper")
|
||||
else
|
||||
source_dirs = {
|
||||
"lobby/glooxwrapper",
|
||||
}
|
||||
extern_libs = {
|
||||
"boost",
|
||||
"gloox",
|
||||
"fmt",
|
||||
}
|
||||
if _OPTIONS["build-shared-glooxwrapper"] then
|
||||
setup_shared_lib_project("glooxwrapper", source_dirs, extern_libs, {})
|
||||
else
|
||||
setup_static_lib_project("glooxwrapper", source_dirs, extern_libs, {})
|
||||
end
|
||||
end
|
||||
else
|
||||
source_dirs = {
|
||||
"lobby/scripting",
|
||||
|
|
|
|||
|
|
@ -2,5 +2,5 @@
|
|||
rem ** Create Visual Studio Workspaces on Windows **
|
||||
|
||||
cd ..\bin
|
||||
if not exist ..\workspaces\vs2017\SKIP_PREMAKE_HERE premake5.exe --file="../premake/premake5.lua" --outpath="../workspaces/vs2017" --build-shared-glooxwrapper %* vs2017
|
||||
if not exist ..\workspaces\vs2017\SKIP_PREMAKE_HERE premake5.exe --file="../premake/premake5.lua" --outpath="../workspaces/vs2017" %* vs2017
|
||||
cd ..\workspaces
|
||||
|
|
|
|||
60
source/lib/external_libraries/gloox.h
Normal file
60
source/lib/external_libraries/gloox.h
Normal file
|
|
@ -0,0 +1,60 @@
|
|||
/* Copyright (C) 2024 Wildfire Games.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included
|
||||
* in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
||||
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
||||
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
||||
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Bring in gloox header+library, with compatibility fixes.
|
||||
*/
|
||||
|
||||
#ifndef INCLUDED_GLOOX
|
||||
#define INCLUDED_GLOOX
|
||||
|
||||
// Needs NOMINMAX or including windows.h breaks c++ standard library. Include
|
||||
// our version which has extra fixes.
|
||||
#include "lib/sysdep/os.h"
|
||||
#if OS_WIN
|
||||
#include "lib/sysdep/os/win/win.h"
|
||||
#endif
|
||||
|
||||
// Conflicts with mozjs
|
||||
#pragma push_macro("lookup")
|
||||
#undef lookup
|
||||
|
||||
#include <gloox/client.h>
|
||||
#include <gloox/connectionlistener.h>
|
||||
#include <gloox/error.h>
|
||||
#include <gloox/glooxversion.h>
|
||||
#include <gloox/jinglecontent.h>
|
||||
#include <gloox/jingleiceudp.h>
|
||||
#include <gloox/jinglesessionhandler.h>
|
||||
#include <gloox/jinglesessionmanager.h>
|
||||
#include <gloox/loghandler.h>
|
||||
#include <gloox/message.h>
|
||||
#include <gloox/mucroom.h>
|
||||
#include <gloox/registration.h>
|
||||
#include <gloox/registrationhandler.h>
|
||||
#include <gloox/stanzaextension.h>
|
||||
#include <gloox/tag.h>
|
||||
#include <gloox/util.h>
|
||||
|
||||
#pragma pop_macro("lookup")
|
||||
|
||||
#endif // #ifndef INCLUDED_GLOOX
|
||||
|
|
@ -21,7 +21,7 @@
|
|||
* GameReport, fairly generic custom stanza extension used
|
||||
* to report game statistics.
|
||||
*/
|
||||
GameReport::GameReport(const glooxwrapper::Tag* tag)
|
||||
GameReport::GameReport(const gloox::Tag* tag)
|
||||
: StanzaExtension(EXTGAMEREPORT)
|
||||
{
|
||||
if (!tag || tag->name() != "report" || tag->xmlns() != XMLNS_GAMEREPORT)
|
||||
|
|
@ -32,12 +32,12 @@ GameReport::GameReport(const glooxwrapper::Tag* tag)
|
|||
/**
|
||||
* Required by gloox, used to serialize the GameReport into XML for sending.
|
||||
*/
|
||||
glooxwrapper::Tag* GameReport::tag() const
|
||||
gloox::Tag* GameReport::tag() const
|
||||
{
|
||||
glooxwrapper::Tag* t = glooxwrapper::Tag::allocate("report");
|
||||
gloox::Tag* t = new gloox::Tag("report");
|
||||
t->setXmlns(XMLNS_GAMEREPORT);
|
||||
|
||||
for (const glooxwrapper::Tag* const& tag : m_GameReport)
|
||||
for (const gloox::Tag* const& tag : m_GameReport)
|
||||
t->addChild(tag->clone());
|
||||
|
||||
return t;
|
||||
|
|
@ -46,13 +46,13 @@ glooxwrapper::Tag* GameReport::tag() const
|
|||
/**
|
||||
* Required by gloox, used to find the GameReport element in a recived IQ.
|
||||
*/
|
||||
const glooxwrapper::string& GameReport::filterString() const
|
||||
const std::string& GameReport::filterString() const
|
||||
{
|
||||
static const glooxwrapper::string filter = "/iq/report[@xmlns='" XMLNS_GAMEREPORT "']";
|
||||
static const std::string filter = "/iq/report[@xmlns='" XMLNS_GAMEREPORT "']";
|
||||
return filter;
|
||||
}
|
||||
|
||||
glooxwrapper::StanzaExtension* GameReport::clone() const
|
||||
gloox::StanzaExtension* GameReport::clone() const
|
||||
{
|
||||
GameReport* q = new GameReport();
|
||||
return q;
|
||||
|
|
@ -64,48 +64,47 @@ glooxwrapper::StanzaExtension* GameReport::clone() const
|
|||
* Example stanza:
|
||||
* <board player="foobar">1200</board>
|
||||
*/
|
||||
BoardListQuery::BoardListQuery(const glooxwrapper::Tag* tag)
|
||||
BoardListQuery::BoardListQuery(const gloox::Tag* tag)
|
||||
: StanzaExtension(EXTBOARDLISTQUERY)
|
||||
{
|
||||
if (!tag || tag->name() != "query" || tag->xmlns() != XMLNS_BOARDLIST)
|
||||
return;
|
||||
|
||||
const glooxwrapper::Tag* c = tag->findTag_clone("query/command");
|
||||
const gloox::Tag* c = tag->findTag("query/command");
|
||||
if (c)
|
||||
m_Command = c->cdata();
|
||||
glooxwrapper::Tag::free(c);
|
||||
for (const glooxwrapper::Tag* const& t : tag->findTagList_clone("query/board"))
|
||||
m_StanzaBoardList.emplace_back(t);
|
||||
for (const gloox::Tag* const& t : tag->findTagList("query/board"))
|
||||
m_StanzaBoardList.emplace_back(t->clone());
|
||||
}
|
||||
|
||||
/**
|
||||
* Required by gloox, used to find the BoardList element in a received IQ.
|
||||
*/
|
||||
const glooxwrapper::string& BoardListQuery::filterString() const
|
||||
const std::string& BoardListQuery::filterString() const
|
||||
{
|
||||
static const glooxwrapper::string filter = "/iq/query[@xmlns='" XMLNS_BOARDLIST "']";
|
||||
static const std::string filter = "/iq/query[@xmlns='" XMLNS_BOARDLIST "']";
|
||||
return filter;
|
||||
}
|
||||
|
||||
/**
|
||||
* Required by gloox, used to serialize the BoardList request into XML for sending.
|
||||
*/
|
||||
glooxwrapper::Tag* BoardListQuery::tag() const
|
||||
gloox::Tag* BoardListQuery::tag() const
|
||||
{
|
||||
glooxwrapper::Tag* t = glooxwrapper::Tag::allocate("query");
|
||||
gloox::Tag* t = new gloox::Tag("query");
|
||||
t->setXmlns(XMLNS_BOARDLIST);
|
||||
|
||||
// Check for ratinglist or boardlist command
|
||||
if (!m_Command.empty())
|
||||
t->addChild(glooxwrapper::Tag::allocate("command", m_Command));
|
||||
t->addChild(new gloox::Tag("command", m_Command));
|
||||
|
||||
for (const glooxwrapper::Tag* const& tag : m_StanzaBoardList)
|
||||
for (const gloox::Tag* const& tag : m_StanzaBoardList)
|
||||
t->addChild(tag->clone());
|
||||
|
||||
return t;
|
||||
}
|
||||
|
||||
glooxwrapper::StanzaExtension* BoardListQuery::clone() const
|
||||
gloox::StanzaExtension* BoardListQuery::clone() const
|
||||
{
|
||||
BoardListQuery* q = new BoardListQuery();
|
||||
return q;
|
||||
|
|
@ -113,8 +112,8 @@ glooxwrapper::StanzaExtension* BoardListQuery::clone() const
|
|||
|
||||
BoardListQuery::~BoardListQuery()
|
||||
{
|
||||
for (const glooxwrapper::Tag* const& t : m_StanzaBoardList)
|
||||
glooxwrapper::Tag::free(t);
|
||||
for (const gloox::Tag* const& t : m_StanzaBoardList)
|
||||
delete t;
|
||||
m_StanzaBoardList.clear();
|
||||
}
|
||||
|
||||
|
|
@ -123,49 +122,48 @@ BoardListQuery::~BoardListQuery()
|
|||
* the listing of games from the server, and register/
|
||||
* unregister/changestate games on the server.
|
||||
*/
|
||||
GameListQuery::GameListQuery(const glooxwrapper::Tag* tag)
|
||||
GameListQuery::GameListQuery(const gloox::Tag* tag)
|
||||
: StanzaExtension(EXTGAMELISTQUERY)
|
||||
{
|
||||
if (!tag || tag->name() != "query" || tag->xmlns() != XMLNS_GAMELIST)
|
||||
return;
|
||||
|
||||
const glooxwrapper::Tag* c = tag->findTag_clone("query/command");
|
||||
const gloox::Tag* c = tag->findTag("query/command");
|
||||
if (c)
|
||||
m_Command = c->cdata();
|
||||
glooxwrapper::Tag::free(c);
|
||||
|
||||
for (const glooxwrapper::Tag* const& t : tag->findTagList_clone("query/game"))
|
||||
m_GameList.emplace_back(t);
|
||||
for (const gloox::Tag* const& t : tag->findTagList("query/game"))
|
||||
m_GameList.emplace_back(t->clone());
|
||||
}
|
||||
|
||||
/**
|
||||
* Required by gloox, used to find the GameList element in a received IQ.
|
||||
*/
|
||||
const glooxwrapper::string& GameListQuery::filterString() const
|
||||
const std::string& GameListQuery::filterString() const
|
||||
{
|
||||
static const glooxwrapper::string filter = "/iq/query[@xmlns='" XMLNS_GAMELIST "']";
|
||||
static const std::string filter = "/iq/query[@xmlns='" XMLNS_GAMELIST "']";
|
||||
return filter;
|
||||
}
|
||||
|
||||
/**
|
||||
* Required by gloox, used to serialize the game object into XML for sending.
|
||||
*/
|
||||
glooxwrapper::Tag* GameListQuery::tag() const
|
||||
gloox::Tag* GameListQuery::tag() const
|
||||
{
|
||||
glooxwrapper::Tag* t = glooxwrapper::Tag::allocate("query");
|
||||
gloox::Tag* t = new gloox::Tag("query");
|
||||
t->setXmlns(XMLNS_GAMELIST);
|
||||
|
||||
// Check for register / unregister command
|
||||
if (!m_Command.empty())
|
||||
t->addChild(glooxwrapper::Tag::allocate("command", m_Command));
|
||||
t->addChild(new gloox::Tag("command", m_Command));
|
||||
|
||||
for (const glooxwrapper::Tag* const& tag : m_GameList)
|
||||
for (const gloox::Tag* const& tag : m_GameList)
|
||||
t->addChild(tag->clone());
|
||||
|
||||
return t;
|
||||
}
|
||||
|
||||
glooxwrapper::StanzaExtension* GameListQuery::clone() const
|
||||
gloox::StanzaExtension* GameListQuery::clone() const
|
||||
{
|
||||
GameListQuery* q = new GameListQuery();
|
||||
return q;
|
||||
|
|
@ -173,8 +171,8 @@ glooxwrapper::StanzaExtension* GameListQuery::clone() const
|
|||
|
||||
GameListQuery::~GameListQuery()
|
||||
{
|
||||
for (const glooxwrapper::Tag* const & t : m_GameList)
|
||||
glooxwrapper::Tag::free(t);
|
||||
for (const gloox::Tag* const & t : m_GameList)
|
||||
delete t;
|
||||
m_GameList.clear();
|
||||
}
|
||||
|
||||
|
|
@ -185,48 +183,47 @@ GameListQuery::~GameListQuery()
|
|||
* <profile player="foobar" highestRating="1500" rank="1895" totalGamesPlayed="50"
|
||||
* wins="25" losses="25" /><command>foobar</command>
|
||||
*/
|
||||
ProfileQuery::ProfileQuery(const glooxwrapper::Tag* tag)
|
||||
ProfileQuery::ProfileQuery(const gloox::Tag* tag)
|
||||
: StanzaExtension(EXTPROFILEQUERY)
|
||||
{
|
||||
if (!tag || tag->name() != "query" || tag->xmlns() != XMLNS_PROFILE)
|
||||
return;
|
||||
|
||||
const glooxwrapper::Tag* c = tag->findTag_clone("query/command");
|
||||
const gloox::Tag* c = tag->findTag("query/command");
|
||||
if (c)
|
||||
m_Command = c->cdata();
|
||||
glooxwrapper::Tag::free(c);
|
||||
|
||||
for (const glooxwrapper::Tag* const& t : tag->findTagList_clone("query/profile"))
|
||||
m_StanzaProfile.emplace_back(t);
|
||||
for (const gloox::Tag* const& t : tag->findTagList("query/profile"))
|
||||
m_StanzaProfile.emplace_back(t->clone());
|
||||
}
|
||||
|
||||
/**
|
||||
* Required by gloox, used to find the Profile element in a received IQ.
|
||||
*/
|
||||
const glooxwrapper::string& ProfileQuery::filterString() const
|
||||
const std::string& ProfileQuery::filterString() const
|
||||
{
|
||||
static const glooxwrapper::string filter = "/iq/query[@xmlns='" XMLNS_PROFILE "']";
|
||||
static const std::string filter = "/iq/query[@xmlns='" XMLNS_PROFILE "']";
|
||||
return filter;
|
||||
}
|
||||
|
||||
/**
|
||||
* Required by gloox, used to serialize the Profile request into XML for sending.
|
||||
*/
|
||||
glooxwrapper::Tag* ProfileQuery::tag() const
|
||||
gloox::Tag* ProfileQuery::tag() const
|
||||
{
|
||||
glooxwrapper::Tag* t = glooxwrapper::Tag::allocate("query");
|
||||
gloox::Tag* t = new gloox::Tag("query");
|
||||
t->setXmlns(XMLNS_PROFILE);
|
||||
|
||||
if (!m_Command.empty())
|
||||
t->addChild(glooxwrapper::Tag::allocate("command", m_Command));
|
||||
t->addChild(new gloox::Tag("command", m_Command));
|
||||
|
||||
for (const glooxwrapper::Tag* const& tag : m_StanzaProfile)
|
||||
for (const gloox::Tag* const& tag : m_StanzaProfile)
|
||||
t->addChild(tag->clone());
|
||||
|
||||
return t;
|
||||
}
|
||||
|
||||
glooxwrapper::StanzaExtension* ProfileQuery::clone() const
|
||||
gloox::StanzaExtension* ProfileQuery::clone() const
|
||||
{
|
||||
ProfileQuery* q = new ProfileQuery();
|
||||
return q;
|
||||
|
|
@ -234,8 +231,8 @@ glooxwrapper::StanzaExtension* ProfileQuery::clone() const
|
|||
|
||||
ProfileQuery::~ProfileQuery()
|
||||
{
|
||||
for (const glooxwrapper::Tag* const& t : m_StanzaProfile)
|
||||
glooxwrapper::Tag::free(t);
|
||||
for (const gloox::Tag* const& t : m_StanzaProfile)
|
||||
delete t;
|
||||
m_StanzaProfile.clear();
|
||||
}
|
||||
|
||||
|
|
@ -243,43 +240,41 @@ ProfileQuery::~ProfileQuery()
|
|||
* LobbyAuth, a custom IQ Stanza, used to send and
|
||||
* receive a security token for hosting authentication.
|
||||
*/
|
||||
LobbyAuth::LobbyAuth(const glooxwrapper::Tag* tag)
|
||||
LobbyAuth::LobbyAuth(const gloox::Tag* tag)
|
||||
: StanzaExtension(EXTLOBBYAUTH)
|
||||
{
|
||||
if (!tag || tag->name() != "auth" || tag->xmlns() != XMLNS_LOBBYAUTH)
|
||||
return;
|
||||
|
||||
const glooxwrapper::Tag* c = tag->findTag_clone("auth/token");
|
||||
const gloox::Tag* c = tag->findTag("auth/token");
|
||||
if (c)
|
||||
m_Token = c->cdata();
|
||||
|
||||
glooxwrapper::Tag::free(c);
|
||||
}
|
||||
|
||||
/**
|
||||
* Required by gloox, used to find the LobbyAuth element in a received IQ.
|
||||
*/
|
||||
const glooxwrapper::string& LobbyAuth::filterString() const
|
||||
const std::string& LobbyAuth::filterString() const
|
||||
{
|
||||
static const glooxwrapper::string filter = "/iq/auth[@xmlns='" XMLNS_LOBBYAUTH "']";
|
||||
static const std::string filter = "/iq/auth[@xmlns='" XMLNS_LOBBYAUTH "']";
|
||||
return filter;
|
||||
}
|
||||
|
||||
/**
|
||||
* Required by gloox, used to serialize the auth object into XML for sending.
|
||||
*/
|
||||
glooxwrapper::Tag* LobbyAuth::tag() const
|
||||
gloox::Tag* LobbyAuth::tag() const
|
||||
{
|
||||
glooxwrapper::Tag* t = glooxwrapper::Tag::allocate("auth");
|
||||
gloox::Tag* t = new gloox::Tag("auth");
|
||||
t->setXmlns(XMLNS_LOBBYAUTH);
|
||||
|
||||
// Check for the auth token
|
||||
if (!m_Token.empty())
|
||||
t->addChild(glooxwrapper::Tag::allocate("token", m_Token));
|
||||
t->addChild(new gloox::Tag("token", m_Token));
|
||||
return t;
|
||||
}
|
||||
|
||||
glooxwrapper::StanzaExtension* LobbyAuth::clone() const
|
||||
gloox::StanzaExtension* LobbyAuth::clone() const
|
||||
{
|
||||
return new LobbyAuth();
|
||||
}
|
||||
|
|
@ -288,78 +283,70 @@ glooxwrapper::StanzaExtension* LobbyAuth::clone() const
|
|||
* ConnectionData, a custom IQ Stanza, used to send and
|
||||
* receive a ip and port of the server.
|
||||
*/
|
||||
ConnectionData::ConnectionData(const glooxwrapper::Tag* tag)
|
||||
ConnectionData::ConnectionData(const gloox::Tag* tag)
|
||||
: StanzaExtension(EXTCONNECTIONDATA)
|
||||
{
|
||||
if (!tag || tag->name() != "connectiondata" || tag->xmlns() != XMLNS_CONNECTIONDATA)
|
||||
return;
|
||||
|
||||
const glooxwrapper::Tag* c = tag->findTag_clone("connectiondata/ip");
|
||||
const gloox::Tag* c = tag->findTag("connectiondata/ip");
|
||||
if (c)
|
||||
m_Ip = c->cdata();
|
||||
const glooxwrapper::Tag* p= tag->findTag_clone("connectiondata/port");
|
||||
const gloox::Tag* p= tag->findTag("connectiondata/port");
|
||||
if (p)
|
||||
m_Port = p->cdata();
|
||||
const glooxwrapper::Tag* pip = tag->findTag_clone("connectiondata/isLocalIP");
|
||||
const gloox::Tag* pip = tag->findTag("connectiondata/isLocalIP");
|
||||
if (pip)
|
||||
m_IsLocalIP = pip->cdata();
|
||||
const glooxwrapper::Tag* s = tag->findTag_clone("connectiondata/useSTUN");
|
||||
const gloox::Tag* s = tag->findTag("connectiondata/useSTUN");
|
||||
if (s)
|
||||
m_UseSTUN = s->cdata();
|
||||
const glooxwrapper::Tag* pw = tag->findTag_clone("connectiondata/password");
|
||||
const gloox::Tag* pw = tag->findTag("connectiondata/password");
|
||||
if (pw)
|
||||
m_Password = pw->cdata();
|
||||
const glooxwrapper::Tag* cs = tag->findTag_clone("connectiondata/clientsalt");
|
||||
const gloox::Tag* cs = tag->findTag("connectiondata/clientsalt");
|
||||
if (cs)
|
||||
m_ClientSalt = cs->cdata();
|
||||
const glooxwrapper::Tag* e = tag->findTag_clone("connectiondata/error");
|
||||
const gloox::Tag* e = tag->findTag("connectiondata/error");
|
||||
if (e)
|
||||
m_Error= e->cdata();
|
||||
|
||||
glooxwrapper::Tag::free(c);
|
||||
glooxwrapper::Tag::free(p);
|
||||
glooxwrapper::Tag::free(pip);
|
||||
glooxwrapper::Tag::free(s);
|
||||
glooxwrapper::Tag::free(pw);
|
||||
glooxwrapper::Tag::free(cs);
|
||||
glooxwrapper::Tag::free(e);
|
||||
}
|
||||
|
||||
/**
|
||||
* Required by gloox, used to find the LobbyAuth element in a received IQ.
|
||||
*/
|
||||
const glooxwrapper::string& ConnectionData::filterString() const
|
||||
const std::string& ConnectionData::filterString() const
|
||||
{
|
||||
static const glooxwrapper::string filter = "/iq/connectiondata[@xmlns='" XMLNS_CONNECTIONDATA "']";
|
||||
static const std::string filter = "/iq/connectiondata[@xmlns='" XMLNS_CONNECTIONDATA "']";
|
||||
return filter;
|
||||
}
|
||||
|
||||
/**
|
||||
* Required by gloox, used to serialize the auth object into XML for sending.
|
||||
*/
|
||||
glooxwrapper::Tag* ConnectionData::tag() const
|
||||
gloox::Tag* ConnectionData::tag() const
|
||||
{
|
||||
glooxwrapper::Tag* t = glooxwrapper::Tag::allocate("connectiondata");
|
||||
gloox::Tag* t = new gloox::Tag("connectiondata");
|
||||
t->setXmlns(XMLNS_CONNECTIONDATA);
|
||||
|
||||
if (!m_Ip.empty())
|
||||
t->addChild(glooxwrapper::Tag::allocate("ip", m_Ip));
|
||||
t->addChild(new gloox::Tag("ip", m_Ip));
|
||||
if (!m_Port.empty())
|
||||
t->addChild(glooxwrapper::Tag::allocate("port", m_Port));
|
||||
t->addChild(new gloox::Tag("port", m_Port));
|
||||
if (!m_IsLocalIP.empty())
|
||||
t->addChild(glooxwrapper::Tag::allocate("isLocalIP", m_IsLocalIP));
|
||||
t->addChild(new gloox::Tag("isLocalIP", m_IsLocalIP));
|
||||
if (!m_UseSTUN.empty())
|
||||
t->addChild(glooxwrapper::Tag::allocate("useSTUN", m_UseSTUN));
|
||||
t->addChild(new gloox::Tag("useSTUN", m_UseSTUN));
|
||||
if (!m_Password.empty())
|
||||
t->addChild(glooxwrapper::Tag::allocate("password", m_Password));
|
||||
t->addChild(new gloox::Tag("password", m_Password));
|
||||
if (!m_ClientSalt.empty())
|
||||
t->addChild(glooxwrapper::Tag::allocate("clientsalt", m_ClientSalt));
|
||||
t->addChild(new gloox::Tag("clientsalt", m_ClientSalt));
|
||||
if (!m_Error.empty())
|
||||
t->addChild(glooxwrapper::Tag::allocate("error", m_Error));
|
||||
t->addChild(new gloox::Tag("error", m_Error));
|
||||
return t;
|
||||
}
|
||||
|
||||
glooxwrapper::StanzaExtension* ConnectionData::clone() const
|
||||
gloox::StanzaExtension* ConnectionData::clone() const
|
||||
{
|
||||
return new ConnectionData();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@
|
|||
#ifndef STANZAEXTENSIONS_H
|
||||
#define STANZAEXTENSIONS_H
|
||||
|
||||
#include "glooxwrapper/glooxwrapper.h"
|
||||
#include "lib/external_libraries/gloox.h"
|
||||
|
||||
#include <vector>
|
||||
|
||||
|
|
@ -44,120 +44,120 @@
|
|||
#define EXTCONNECTIONDATA 1408
|
||||
#define XMLNS_CONNECTIONDATA "jabber:iq:connectiondata"
|
||||
|
||||
class ConnectionData : public glooxwrapper::StanzaExtension
|
||||
class ConnectionData : public gloox::StanzaExtension
|
||||
{
|
||||
public:
|
||||
ConnectionData(const glooxwrapper::Tag* tag = 0);
|
||||
ConnectionData(const gloox::Tag* tag = 0);
|
||||
|
||||
// Following four methods are all required by gloox
|
||||
virtual StanzaExtension* newInstance(const glooxwrapper::Tag* tag) const
|
||||
StanzaExtension* newInstance(const gloox::Tag* tag) const override
|
||||
{
|
||||
return new ConnectionData(tag);
|
||||
}
|
||||
virtual const glooxwrapper::string& filterString() const;
|
||||
virtual glooxwrapper::Tag* tag() const;
|
||||
virtual glooxwrapper::StanzaExtension* clone() const;
|
||||
const std::string& filterString() const override;
|
||||
gloox::Tag* tag() const override;
|
||||
gloox::StanzaExtension* clone() const override;
|
||||
|
||||
glooxwrapper::string m_Ip;
|
||||
glooxwrapper::string m_Port;
|
||||
glooxwrapper::string m_IsLocalIP;
|
||||
glooxwrapper::string m_UseSTUN;
|
||||
glooxwrapper::string m_Password;
|
||||
glooxwrapper::string m_ClientSalt;
|
||||
glooxwrapper::string m_Error;
|
||||
std::string m_Ip;
|
||||
std::string m_Port;
|
||||
std::string m_IsLocalIP;
|
||||
std::string m_UseSTUN;
|
||||
std::string m_Password;
|
||||
std::string m_ClientSalt;
|
||||
std::string m_Error;
|
||||
};
|
||||
|
||||
class GameReport : public glooxwrapper::StanzaExtension
|
||||
class GameReport : public gloox::StanzaExtension
|
||||
{
|
||||
public:
|
||||
GameReport(const glooxwrapper::Tag* tag = 0);
|
||||
GameReport(const gloox::Tag* tag = 0);
|
||||
|
||||
// Following four methods are all required by gloox
|
||||
virtual StanzaExtension* newInstance(const glooxwrapper::Tag* tag) const
|
||||
StanzaExtension* newInstance(const gloox::Tag* tag) const override
|
||||
{
|
||||
return new GameReport(tag);
|
||||
}
|
||||
virtual const glooxwrapper::string& filterString() const;
|
||||
virtual glooxwrapper::Tag* tag() const;
|
||||
virtual glooxwrapper::StanzaExtension* clone() const;
|
||||
const std::string& filterString() const override;
|
||||
gloox::Tag* tag() const override;
|
||||
gloox::StanzaExtension* clone() const override;
|
||||
|
||||
std::vector<const glooxwrapper::Tag*> m_GameReport;
|
||||
std::vector<const gloox::Tag*> m_GameReport;
|
||||
};
|
||||
|
||||
class GameListQuery : public glooxwrapper::StanzaExtension
|
||||
class GameListQuery : public gloox::StanzaExtension
|
||||
{
|
||||
public:
|
||||
GameListQuery(const glooxwrapper::Tag* tag = 0);
|
||||
GameListQuery(const gloox::Tag* tag = 0);
|
||||
|
||||
// Following four methods are all required by gloox
|
||||
virtual StanzaExtension* newInstance(const glooxwrapper::Tag* tag) const
|
||||
StanzaExtension* newInstance(const gloox::Tag* tag) const override
|
||||
{
|
||||
return new GameListQuery(tag);
|
||||
}
|
||||
virtual const glooxwrapper::string& filterString() const;
|
||||
virtual glooxwrapper::Tag* tag() const;
|
||||
virtual glooxwrapper::StanzaExtension* clone() const;
|
||||
const std::string& filterString() const override;
|
||||
gloox::Tag* tag() const override;
|
||||
gloox::StanzaExtension* clone() const override;
|
||||
|
||||
~GameListQuery();
|
||||
|
||||
glooxwrapper::string m_Command;
|
||||
std::vector<const glooxwrapper::Tag*> m_GameList;
|
||||
std::string m_Command;
|
||||
std::vector<const gloox::Tag*> m_GameList;
|
||||
};
|
||||
|
||||
class BoardListQuery : public glooxwrapper::StanzaExtension
|
||||
class BoardListQuery : public gloox::StanzaExtension
|
||||
{
|
||||
public:
|
||||
BoardListQuery(const glooxwrapper::Tag* tag = 0);
|
||||
BoardListQuery(const gloox::Tag* tag = 0);
|
||||
|
||||
// Following four methods are all required by gloox
|
||||
virtual StanzaExtension* newInstance(const glooxwrapper::Tag* tag) const
|
||||
StanzaExtension* newInstance(const gloox::Tag* tag) const override
|
||||
{
|
||||
return new BoardListQuery(tag);
|
||||
}
|
||||
virtual const glooxwrapper::string& filterString() const;
|
||||
virtual glooxwrapper::Tag* tag() const;
|
||||
virtual glooxwrapper::StanzaExtension* clone() const;
|
||||
const std::string& filterString() const override;
|
||||
gloox::Tag* tag() const override;
|
||||
gloox::StanzaExtension* clone() const override;
|
||||
|
||||
~BoardListQuery();
|
||||
|
||||
glooxwrapper::string m_Command;
|
||||
std::vector<const glooxwrapper::Tag*> m_StanzaBoardList;
|
||||
std::string m_Command;
|
||||
std::vector<const gloox::Tag*> m_StanzaBoardList;
|
||||
};
|
||||
|
||||
class ProfileQuery : public glooxwrapper::StanzaExtension
|
||||
class ProfileQuery : public gloox::StanzaExtension
|
||||
{
|
||||
public:
|
||||
ProfileQuery(const glooxwrapper::Tag* tag = 0);
|
||||
ProfileQuery(const gloox::Tag* tag = 0);
|
||||
|
||||
// Following four methods are all required by gloox
|
||||
virtual StanzaExtension* newInstance(const glooxwrapper::Tag* tag) const
|
||||
StanzaExtension* newInstance(const gloox::Tag* tag) const override
|
||||
{
|
||||
return new ProfileQuery(tag);
|
||||
}
|
||||
virtual const glooxwrapper::string& filterString() const;
|
||||
virtual glooxwrapper::Tag* tag() const;
|
||||
virtual glooxwrapper::StanzaExtension* clone() const;
|
||||
const std::string& filterString() const override;
|
||||
gloox::Tag* tag() const override;
|
||||
gloox::StanzaExtension* clone() const override;
|
||||
|
||||
~ProfileQuery();
|
||||
|
||||
glooxwrapper::string m_Command;
|
||||
std::vector<const glooxwrapper::Tag*> m_StanzaProfile;
|
||||
std::string m_Command;
|
||||
std::vector<const gloox::Tag*> m_StanzaProfile;
|
||||
};
|
||||
|
||||
class LobbyAuth : public glooxwrapper::StanzaExtension
|
||||
class LobbyAuth : public gloox::StanzaExtension
|
||||
{
|
||||
public:
|
||||
LobbyAuth(const glooxwrapper::Tag* tag = 0);
|
||||
LobbyAuth(const gloox::Tag* tag = 0);
|
||||
|
||||
// Following four methods are all required by gloox
|
||||
virtual StanzaExtension* newInstance(const glooxwrapper::Tag* tag) const
|
||||
StanzaExtension* newInstance(const gloox::Tag* tag) const override
|
||||
{
|
||||
return new LobbyAuth(tag);
|
||||
}
|
||||
virtual const glooxwrapper::string& filterString() const;
|
||||
virtual glooxwrapper::Tag* tag() const;
|
||||
virtual glooxwrapper::StanzaExtension* clone() const;
|
||||
const std::string& filterString() const override;
|
||||
gloox::Tag* tag() const override;
|
||||
gloox::StanzaExtension* clone() const override;
|
||||
|
||||
glooxwrapper::string m_Token;
|
||||
std::string m_Token;
|
||||
};
|
||||
#endif // STANZAEXTENSIONS_H
|
||||
|
|
|
|||
|
|
@ -40,23 +40,15 @@
|
|||
#else
|
||||
#define DbgXMPP(x) std::cout << x << std::endl;
|
||||
|
||||
static std::string tag_xml(const glooxwrapper::IQ& iq)
|
||||
static std::string tag_xml(const gloox::IQ& iq)
|
||||
{
|
||||
std::string ret;
|
||||
glooxwrapper::Tag* tag = iq.tag();
|
||||
ret = tag->xml().to_string();
|
||||
glooxwrapper::Tag::free(tag);
|
||||
return ret;
|
||||
return iq.tag()->xml();
|
||||
}
|
||||
#endif
|
||||
|
||||
static std::string tag_name(const glooxwrapper::IQ& iq)
|
||||
static std::string tag_name(const gloox::IQ& iq)
|
||||
{
|
||||
std::string ret;
|
||||
glooxwrapper::Tag* tag = iq.tag();
|
||||
ret = tag->name().to_string();
|
||||
glooxwrapper::Tag::free(tag);
|
||||
return ret;
|
||||
return iq.tag()->name();
|
||||
}
|
||||
|
||||
IXmppClient* IXmppClient::create(const ScriptInterface* scriptInterface, const std::string& sUsername, const std::string& sPassword, const std::string& sRoom, const std::string& sNick, const int historyRequestSize,bool regOpt)
|
||||
|
|
@ -106,15 +98,15 @@ XmppClient::XmppClient(const ScriptInterface* scriptInterface, const std::string
|
|||
m_xpartamuppId = sXpartamupp + "@" + m_server + "/CC";
|
||||
m_echelonId = sEchelon + "@" + m_server + "/CC";
|
||||
// Generate a unique, unpredictable resource to allow multiple 0 A.D. instances to connect to the lobby.
|
||||
glooxwrapper::JID clientJid(sUsername + "@" + m_server + "/0ad-" + ps_generate_guid());
|
||||
glooxwrapper::JID roomJid(m_room + "@conference." + m_server + "/" + sNick);
|
||||
gloox::JID clientJid(sUsername + "@" + m_server + "/0ad-" + ps_generate_guid());
|
||||
gloox::JID roomJid(m_room + "@conference." + m_server + "/" + sNick);
|
||||
|
||||
// If we are connecting, use the full jid and a password
|
||||
// If we are registering, only use the server name
|
||||
if (!regOpt)
|
||||
m_client = new glooxwrapper::Client(clientJid, sPassword);
|
||||
m_client = new gloox::Client(clientJid, sPassword);
|
||||
else
|
||||
m_client = new glooxwrapper::Client(m_server);
|
||||
m_client = new gloox::Client(m_server);
|
||||
|
||||
// Optionally join without a TLS certificate, so a local server can be tested quickly.
|
||||
// Security risks from malicious JS mods can be mitigated if this option and also the hostname and login are shielded from JS access.
|
||||
|
|
@ -152,25 +144,26 @@ XmppClient::XmppClient(const ScriptInterface* scriptInterface, const std::string
|
|||
m_client->registerMessageHandler(this);
|
||||
|
||||
// Uncomment to see the raw stanzas
|
||||
//m_client->getWrapped()->logInstance().registerLogHandler( gloox::LogLevelDebug, gloox::LogAreaAll, this );
|
||||
// m_client->logInstance().registerLogHandler(gloox::LogLevelDebug, gloox::LogAreaAll, this);
|
||||
|
||||
if (!regOpt)
|
||||
{
|
||||
// Create a Multi User Chat Room
|
||||
m_mucRoom = new glooxwrapper::MUCRoom(m_client, roomJid, this, 0);
|
||||
m_mucRoom = new gloox::MUCRoom(m_client, roomJid, this, 0);
|
||||
// Get room history.
|
||||
m_mucRoom->setRequestHistory(historyRequestSize, gloox::MUCRoom::HistoryMaxStanzas);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Registration
|
||||
m_registration = new glooxwrapper::Registration(m_client);
|
||||
m_registration = new gloox::Registration(m_client);
|
||||
m_registration->registerRegistrationHandler(this);
|
||||
}
|
||||
|
||||
m_sessionManager = new glooxwrapper::SessionManager(m_client, this);
|
||||
m_sessionManager = new gloox::Jingle::SessionManager(m_client, this);
|
||||
// Register plugins to allow gloox parse them in incoming sessions
|
||||
m_sessionManager->registerPlugins();
|
||||
m_sessionManager->registerPlugin(new gloox::Jingle::Content());
|
||||
m_sessionManager->registerPlugin(new gloox::Jingle::ICEUDP());
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -188,12 +181,12 @@ XmppClient::~XmppClient()
|
|||
|
||||
delete m_client;
|
||||
|
||||
for (const glooxwrapper::Tag* const& t : m_GameList)
|
||||
glooxwrapper::Tag::free(t);
|
||||
for (const glooxwrapper::Tag* const& t : m_BoardList)
|
||||
glooxwrapper::Tag::free(t);
|
||||
for (const glooxwrapper::Tag* const& t : m_Profile)
|
||||
glooxwrapper::Tag::free(t);
|
||||
for (const gloox::Tag* const& t : m_GameList)
|
||||
delete t;
|
||||
for (const gloox::Tag* const& t : m_BoardList)
|
||||
delete t;
|
||||
for (const gloox::Tag* const& t : m_Profile)
|
||||
delete t;
|
||||
|
||||
if (m_ScriptInterface)
|
||||
JS_RemoveExtraGCRootsTracer(m_ScriptInterface->GetGeneralJSContext(), XmppClient::Trace, this);
|
||||
|
|
@ -269,12 +262,12 @@ void XmppClient::onDisconnect(gloox::ConnectionError error)
|
|||
m_mucRoom->leave();
|
||||
|
||||
// Clear game, board and player lists.
|
||||
for (const glooxwrapper::Tag* const& t : m_GameList)
|
||||
glooxwrapper::Tag::free(t);
|
||||
for (const glooxwrapper::Tag* const& t : m_BoardList)
|
||||
glooxwrapper::Tag::free(t);
|
||||
for (const glooxwrapper::Tag* const& t : m_Profile)
|
||||
glooxwrapper::Tag::free(t);
|
||||
for (const gloox::Tag* const& t : m_GameList)
|
||||
delete t;
|
||||
for (const gloox::Tag* const& t : m_BoardList)
|
||||
delete t;
|
||||
for (const gloox::Tag* const& t : m_Profile)
|
||||
delete t;
|
||||
|
||||
m_BoardList.clear();
|
||||
m_GameList.clear();
|
||||
|
|
@ -296,7 +289,7 @@ void XmppClient::onDisconnect(gloox::ConnectionError error)
|
|||
/**
|
||||
* Handle TLS connection.
|
||||
*/
|
||||
bool XmppClient::onTLSConnect(const glooxwrapper::CertInfo& info)
|
||||
bool XmppClient::onTLSConnect(const gloox::CertInfo& info)
|
||||
{
|
||||
DbgXMPP("onTLSConnect");
|
||||
DbgXMPP(
|
||||
|
|
@ -320,7 +313,7 @@ bool XmppClient::onTLSConnect(const glooxwrapper::CertInfo& info)
|
|||
/**
|
||||
* Handle MUC room errors
|
||||
*/
|
||||
void XmppClient::handleMUCError(glooxwrapper::MUCRoom& UNUSED(room), gloox::StanzaError err)
|
||||
void XmppClient::handleMUCError(gloox::MUCRoom* UNUSED(room), gloox::StanzaError err)
|
||||
{
|
||||
DbgXMPP("MUC Error " << ": " << StanzaErrorToString(err));
|
||||
CreateGUIMessage("system", "error", std::time(nullptr), "text", err);
|
||||
|
|
@ -335,12 +328,12 @@ void XmppClient::handleMUCError(glooxwrapper::MUCRoom& UNUSED(room), gloox::Stan
|
|||
*/
|
||||
void XmppClient::SendIqGetBoardList()
|
||||
{
|
||||
glooxwrapper::JID echelonJid(m_echelonId);
|
||||
gloox::JID echelonJid(m_echelonId);
|
||||
|
||||
// Send IQ
|
||||
BoardListQuery* b = new BoardListQuery();
|
||||
b->m_Command = "getleaderboard";
|
||||
glooxwrapper::IQ iq(gloox::IQ::Get, echelonJid, m_client->getID());
|
||||
gloox::IQ iq(gloox::IQ::Get, echelonJid, m_client->getID());
|
||||
iq.addExtension(b);
|
||||
DbgXMPP("SendIqGetBoardList [" << tag_xml(iq) << "]");
|
||||
m_client->send(iq);
|
||||
|
|
@ -351,12 +344,12 @@ void XmppClient::SendIqGetBoardList()
|
|||
*/
|
||||
void XmppClient::SendIqGetProfile(const std::string& player)
|
||||
{
|
||||
glooxwrapper::JID echelonJid(m_echelonId);
|
||||
gloox::JID echelonJid(m_echelonId);
|
||||
|
||||
// Send IQ
|
||||
ProfileQuery* b = new ProfileQuery();
|
||||
b->m_Command = player;
|
||||
glooxwrapper::IQ iq(gloox::IQ::Get, echelonJid, m_client->getID());
|
||||
gloox::IQ iq(gloox::IQ::Get, echelonJid, m_client->getID());
|
||||
iq.addExtension(b);
|
||||
DbgXMPP("SendIqGetProfile [" << tag_xml(iq) << "]");
|
||||
m_client->send(iq);
|
||||
|
|
@ -367,16 +360,16 @@ void XmppClient::SendIqGetProfile(const std::string& player)
|
|||
*/
|
||||
void XmppClient::SendIqGetConnectionData(const std::string& jid, const std::string& password, const std::string& clientSalt, bool localIP)
|
||||
{
|
||||
glooxwrapper::JID targetJID(jid);
|
||||
gloox::JID targetJID(jid);
|
||||
|
||||
ConnectionData* connectionData = new ConnectionData();
|
||||
connectionData->m_Password = password;
|
||||
connectionData->m_ClientSalt = clientSalt;
|
||||
connectionData->m_IsLocalIP = localIP ? "1" : "0";
|
||||
glooxwrapper::IQ iq(gloox::IQ::Get, targetJID, m_client->getID());
|
||||
gloox::IQ iq(gloox::IQ::Get, targetJID, m_client->getID());
|
||||
iq.addExtension(connectionData);
|
||||
m_connectionDataJid = iq.from().full();
|
||||
m_connectionDataIqId = iq.id().to_string();
|
||||
m_connectionDataIqId = iq.id();
|
||||
DbgXMPP("SendIqGetConnectionData [" << tag_xml(iq) << "]");
|
||||
m_client->send(iq);
|
||||
}
|
||||
|
|
@ -388,11 +381,11 @@ void XmppClient::SendIqGetConnectionData(const std::string& jid, const std::stri
|
|||
*/
|
||||
void XmppClient::SendIqGameReport(const ScriptRequest& rq, JS::HandleValue data)
|
||||
{
|
||||
glooxwrapper::JID echelonJid(m_echelonId);
|
||||
gloox::JID echelonJid(m_echelonId);
|
||||
|
||||
// Setup some base stanza attributes
|
||||
GameReport* game = new GameReport();
|
||||
glooxwrapper::Tag* report = glooxwrapper::Tag::allocate("game");
|
||||
gloox::Tag* report = new gloox::Tag("game");
|
||||
|
||||
// Iterate through all the properties reported and add them to the stanza.
|
||||
std::vector<std::string> properties;
|
||||
|
|
@ -408,7 +401,7 @@ void XmppClient::SendIqGameReport(const ScriptRequest& rq, JS::HandleValue data)
|
|||
game->m_GameReport.emplace_back(report);
|
||||
|
||||
// Send IQ
|
||||
glooxwrapper::IQ iq(gloox::IQ::Set, echelonJid, m_client->getID());
|
||||
gloox::IQ iq(gloox::IQ::Set, echelonJid, m_client->getID());
|
||||
iq.addExtension(game);
|
||||
DbgXMPP("SendGameReport [" << tag_xml(iq) << "]");
|
||||
m_client->send(iq);
|
||||
|
|
@ -421,12 +414,12 @@ void XmppClient::SendIqGameReport(const ScriptRequest& rq, JS::HandleValue data)
|
|||
*/
|
||||
void XmppClient::SendIqRegisterGame(const ScriptRequest& rq, JS::HandleValue data)
|
||||
{
|
||||
glooxwrapper::JID xpartamuppJid(m_xpartamuppId);
|
||||
gloox::JID xpartamuppJid(m_xpartamuppId);
|
||||
|
||||
// Setup some base stanza attributes
|
||||
std::unique_ptr<GameListQuery> g = std::make_unique<GameListQuery>();
|
||||
g->m_Command = "register";
|
||||
glooxwrapper::Tag* game = glooxwrapper::Tag::allocate("game");
|
||||
gloox::Tag* game = new gloox::Tag("game");
|
||||
|
||||
// Iterate through all the properties reported and add them to the stanza.
|
||||
std::vector<std::string> properties;
|
||||
|
|
@ -452,7 +445,7 @@ void XmppClient::SendIqRegisterGame(const ScriptRequest& rq, JS::HandleValue dat
|
|||
g->m_GameList.emplace_back(game);
|
||||
|
||||
// Send IQ
|
||||
glooxwrapper::IQ iq(gloox::IQ::Set, xpartamuppJid, m_client->getID());
|
||||
gloox::IQ iq(gloox::IQ::Set, xpartamuppJid, m_client->getID());
|
||||
iq.addExtension(g.release());
|
||||
DbgXMPP("SendIqRegisterGame [" << tag_xml(iq) << "]");
|
||||
m_client->send(iq);
|
||||
|
|
@ -463,14 +456,14 @@ void XmppClient::SendIqRegisterGame(const ScriptRequest& rq, JS::HandleValue dat
|
|||
*/
|
||||
void XmppClient::SendIqUnregisterGame()
|
||||
{
|
||||
glooxwrapper::JID xpartamuppJid(m_xpartamuppId);
|
||||
gloox::JID xpartamuppJid(m_xpartamuppId);
|
||||
|
||||
// Send IQ
|
||||
GameListQuery* g = new GameListQuery();
|
||||
g->m_Command = "unregister";
|
||||
g->m_GameList.emplace_back(glooxwrapper::Tag::allocate("game"));
|
||||
g->m_GameList.emplace_back(new gloox::Tag("game"));
|
||||
|
||||
glooxwrapper::IQ iq(gloox::IQ::Set, xpartamuppJid, m_client->getID());
|
||||
gloox::IQ iq(gloox::IQ::Set, xpartamuppJid, m_client->getID());
|
||||
iq.addExtension(g);
|
||||
DbgXMPP("SendIqUnregisterGame [" << tag_xml(iq) << "]");
|
||||
m_client->send(iq);
|
||||
|
|
@ -485,17 +478,17 @@ void XmppClient::SendIqUnregisterGame()
|
|||
*/
|
||||
void XmppClient::SendIqChangeStateGame(const std::string& nbp, const std::string& players)
|
||||
{
|
||||
glooxwrapper::JID xpartamuppJid(m_xpartamuppId);
|
||||
gloox::JID xpartamuppJid(m_xpartamuppId);
|
||||
|
||||
// Send IQ
|
||||
GameListQuery* g = new GameListQuery();
|
||||
g->m_Command = "changestate";
|
||||
glooxwrapper::Tag* game = glooxwrapper::Tag::allocate("game");
|
||||
gloox::Tag* game = new gloox::Tag("game");
|
||||
game->addAttribute("nbp", nbp);
|
||||
game->addAttribute("players", players);
|
||||
g->m_GameList.emplace_back(game);
|
||||
|
||||
glooxwrapper::IQ iq(gloox::IQ::Set, xpartamuppJid, m_client->getID());
|
||||
gloox::IQ iq(gloox::IQ::Set, xpartamuppJid, m_client->getID());
|
||||
iq.addExtension(g);
|
||||
DbgXMPP("SendIqChangeStateGame [" << tag_xml(iq) << "]");
|
||||
m_client->send(iq);
|
||||
|
|
@ -513,8 +506,8 @@ void XmppClient::SendIqLobbyAuth(const std::string& to, const std::string& token
|
|||
LobbyAuth* auth = new LobbyAuth();
|
||||
auth->m_Token = token;
|
||||
|
||||
glooxwrapper::JID clientJid(to);
|
||||
glooxwrapper::IQ iq(gloox::IQ::Set, clientJid, m_client->getID());
|
||||
gloox::JID clientJid(to);
|
||||
gloox::IQ iq(gloox::IQ::Set, clientJid, m_client->getID());
|
||||
iq.addExtension(auth);
|
||||
DbgXMPP("SendIqLobbyAuth [" << tag_xml(iq) << "]");
|
||||
m_client->send(iq);
|
||||
|
|
@ -524,15 +517,19 @@ void XmppClient::SendIqLobbyAuth(const std::string& to, const std::string& token
|
|||
* Account registration *
|
||||
*****************************************************/
|
||||
|
||||
void XmppClient::handleRegistrationFields(const glooxwrapper::JID&, int fields, glooxwrapper::string)
|
||||
void XmppClient::handleRegistrationFields(const gloox::JID&, int fields, std::string)
|
||||
{
|
||||
glooxwrapper::RegistrationFields vals;
|
||||
gloox::RegistrationFields vals;
|
||||
vals.username = m_username;
|
||||
vals.password = m_password;
|
||||
m_registration->createAccount(fields, vals);
|
||||
}
|
||||
|
||||
void XmppClient::handleRegistrationResult(const glooxwrapper::JID&, gloox::RegistrationResult result)
|
||||
#if GLOOXVERSION >= 0x010100
|
||||
void XmppClient::handleRegistrationResult(const gloox::JID&, gloox::RegistrationResult result, const gloox::Error* /*error*/)
|
||||
#else
|
||||
void XmppClient::handleRegistrationResult(const gloox::JID&, gloox::RegistrationResult result)
|
||||
#endif
|
||||
{
|
||||
if (result == gloox::RegistrationSuccess)
|
||||
CreateGUIMessage("system", "registered", std::time(nullptr));
|
||||
|
|
@ -542,17 +539,17 @@ void XmppClient::handleRegistrationResult(const glooxwrapper::JID&, gloox::Regis
|
|||
disconnect();
|
||||
}
|
||||
|
||||
void XmppClient::handleAlreadyRegistered(const glooxwrapper::JID&)
|
||||
void XmppClient::handleAlreadyRegistered(const gloox::JID&)
|
||||
{
|
||||
DbgXMPP("the account already exists");
|
||||
}
|
||||
|
||||
void XmppClient::handleDataForm(const glooxwrapper::JID&, const glooxwrapper::DataForm&)
|
||||
void XmppClient::handleDataForm(const gloox::JID&, const gloox::DataForm&)
|
||||
{
|
||||
DbgXMPP("dataForm received");
|
||||
}
|
||||
|
||||
void XmppClient::handleOOB(const glooxwrapper::JID&, const glooxwrapper::OOB&)
|
||||
void XmppClient::handleOOB(const gloox::JID&, const gloox::OOB&)
|
||||
{
|
||||
DbgXMPP("OOB registration requested");
|
||||
}
|
||||
|
|
@ -572,7 +569,7 @@ JS::Value XmppClient::GUIGetPlayerList(const ScriptRequest& rq)
|
|||
Script::CreateArray(rq, &ret);
|
||||
int j = 0;
|
||||
|
||||
for (const std::pair<const glooxwrapper::string, SPlayer>& p : m_PlayerMap)
|
||||
for (const std::pair<const std::string, SPlayer>& p : m_PlayerMap)
|
||||
{
|
||||
JS::RootedValue player(rq.cx);
|
||||
|
||||
|
|
@ -604,7 +601,7 @@ JS::Value XmppClient::GUIGetGameList(const ScriptRequest& rq)
|
|||
"nbp", "maxnbp", "players", "mapName", "niceMapName", "mapSize", "mapType",
|
||||
"victoryConditions", "startTime", "mods" };
|
||||
|
||||
for(const glooxwrapper::Tag* const& t : m_GameList)
|
||||
for(const gloox::Tag* const& t : m_GameList)
|
||||
{
|
||||
JS::RootedValue game(rq.cx);
|
||||
Script::CreateObject(rq, &game);
|
||||
|
|
@ -630,7 +627,7 @@ JS::Value XmppClient::GUIGetBoardList(const ScriptRequest& rq)
|
|||
|
||||
const char* attributes[] = { "name", "rank", "rating" };
|
||||
|
||||
for(const glooxwrapper::Tag* const& t : m_BoardList)
|
||||
for(const gloox::Tag* const& t : m_BoardList)
|
||||
{
|
||||
JS::RootedValue board(rq.cx);
|
||||
Script::CreateObject(rq, &board);
|
||||
|
|
@ -656,7 +653,7 @@ JS::Value XmppClient::GUIGetProfile(const ScriptRequest& rq)
|
|||
|
||||
const char* stats[] = { "player", "rating", "totalGamesPlayed", "highestRating", "wins", "losses", "rank" };
|
||||
|
||||
for (const glooxwrapper::Tag* const& t : m_Profile)
|
||||
for (const gloox::Tag* const& t : m_Profile)
|
||||
{
|
||||
JS::RootedValue profile(rq.cx);
|
||||
Script::CreateObject(rq, &profile);
|
||||
|
|
@ -799,7 +796,7 @@ void XmppClient::SendMUCMessage(const std::string& message)
|
|||
/**
|
||||
* Handle a room message.
|
||||
*/
|
||||
void XmppClient::handleMUCMessage(glooxwrapper::MUCRoom& UNUSED(room), const glooxwrapper::Message& msg, bool priv)
|
||||
void XmppClient::handleMUCMessage(gloox::MUCRoom* UNUSED(room), const gloox::Message& msg, bool priv)
|
||||
{
|
||||
DbgXMPP(msg.from().resource() << " said " << msg.body());
|
||||
|
||||
|
|
@ -814,7 +811,7 @@ void XmppClient::handleMUCMessage(glooxwrapper::MUCRoom& UNUSED(room), const glo
|
|||
/**
|
||||
* Handle a private message.
|
||||
*/
|
||||
void XmppClient::handleMessage(const glooxwrapper::Message& msg, glooxwrapper::MessageSession*)
|
||||
void XmppClient::handleMessage(const gloox::Message& msg, gloox::MessageSession*)
|
||||
{
|
||||
DbgXMPP("type " << msg.subtype() << ", subject " << msg.subject()
|
||||
<< ", message " << msg.body() << ", thread id " << msg.thread());
|
||||
|
|
@ -831,7 +828,7 @@ void XmppClient::handleMessage(const glooxwrapper::Message& msg, glooxwrapper::M
|
|||
/**
|
||||
* Handle portions of messages containing custom stanza extensions.
|
||||
*/
|
||||
bool XmppClient::handleIq(const glooxwrapper::IQ& iq)
|
||||
bool XmppClient::handleIq(const gloox::IQ& iq)
|
||||
{
|
||||
DbgXMPP("handleIq [" << tag_xml(iq) << "]");
|
||||
|
||||
|
|
@ -851,7 +848,7 @@ bool XmppClient::handleIq(const glooxwrapper::IQ& iq)
|
|||
return true;
|
||||
}
|
||||
|
||||
if (!m_connectionDataIqId.empty() && m_connectionDataIqId.compare(iq.id().to_string()) != 0) {
|
||||
if (!m_connectionDataIqId.empty() && m_connectionDataIqId.compare(iq.id()) != 0) {
|
||||
LOGMESSAGE("XmppClient: Received connection data with invalid id");
|
||||
return true;
|
||||
}
|
||||
|
|
@ -862,7 +859,7 @@ bool XmppClient::handleIq(const glooxwrapper::IQ& iq)
|
|||
return true;
|
||||
}
|
||||
|
||||
g_NetClient->SetupServerData(cd->m_Ip.to_string(), stoi(cd->m_Port.to_string()), !cd->m_UseSTUN.empty());
|
||||
g_NetClient->SetupServerData(cd->m_Ip, stoi(cd->m_Port), !cd->m_UseSTUN.empty());
|
||||
g_NetClient->TryToConnect(iq.from().full(), !cd->m_IsLocalIP.empty());
|
||||
}
|
||||
if (gq)
|
||||
|
|
@ -880,7 +877,7 @@ bool XmppClient::handleIq(const glooxwrapper::IQ& iq)
|
|||
LOGWARNING("XmppClient: Received empty game list in response to Game Register");
|
||||
return true;
|
||||
}
|
||||
std::string publicIP = gq->m_GameList.front()->findAttribute("ip").to_string();
|
||||
std::string publicIP = gq->m_GameList.front()->findAttribute("ip");
|
||||
if (publicIP.empty())
|
||||
{
|
||||
LOGWARNING("XmppClient: Received game with no IP in response to Game Register");
|
||||
|
|
@ -890,11 +887,11 @@ bool XmppClient::handleIq(const glooxwrapper::IQ& iq)
|
|||
return true;
|
||||
}
|
||||
|
||||
for (const glooxwrapper::Tag* const& t : m_GameList)
|
||||
glooxwrapper::Tag::free(t);
|
||||
for (const gloox::Tag* const& t : m_GameList)
|
||||
delete t;
|
||||
m_GameList.clear();
|
||||
|
||||
for (const glooxwrapper::Tag* const& t : gq->m_GameList)
|
||||
for (const gloox::Tag* const& t : gq->m_GameList)
|
||||
m_GameList.emplace_back(t->clone());
|
||||
|
||||
CreateGUIMessage("game", "gamelist", std::time(nullptr));
|
||||
|
|
@ -909,18 +906,18 @@ bool XmppClient::handleIq(const glooxwrapper::IQ& iq)
|
|||
|
||||
if (bq->m_Command == "boardlist")
|
||||
{
|
||||
for (const glooxwrapper::Tag* const& t : m_BoardList)
|
||||
glooxwrapper::Tag::free(t);
|
||||
for (const gloox::Tag* const& t : m_BoardList)
|
||||
delete t;
|
||||
m_BoardList.clear();
|
||||
|
||||
for (const glooxwrapper::Tag* const& t : bq->m_StanzaBoardList)
|
||||
for (const gloox::Tag* const& t : bq->m_StanzaBoardList)
|
||||
m_BoardList.emplace_back(t->clone());
|
||||
|
||||
CreateGUIMessage("game", "leaderboard", std::time(nullptr));
|
||||
}
|
||||
else if (bq->m_Command == "ratinglist")
|
||||
{
|
||||
for (const glooxwrapper::Tag* const& t : bq->m_StanzaBoardList)
|
||||
for (const gloox::Tag* const& t : bq->m_StanzaBoardList)
|
||||
{
|
||||
const PlayerMap::iterator it = m_PlayerMap.find(t->findAttribute("name"));
|
||||
if (it != m_PlayerMap.end())
|
||||
|
|
@ -940,11 +937,11 @@ bool XmppClient::handleIq(const glooxwrapper::IQ& iq)
|
|||
return true;
|
||||
}
|
||||
|
||||
for (const glooxwrapper::Tag* const& t : m_Profile)
|
||||
glooxwrapper::Tag::free(t);
|
||||
for (const gloox::Tag* const& t : m_Profile)
|
||||
delete t;
|
||||
m_Profile.clear();
|
||||
|
||||
for (const glooxwrapper::Tag* const& t : pq->m_StanzaProfile)
|
||||
for (const gloox::Tag* const& t : pq->m_StanzaProfile)
|
||||
m_Profile.emplace_back(t->clone());
|
||||
|
||||
CreateGUIMessage("game", "profile", std::time(nullptr));
|
||||
|
|
@ -955,13 +952,13 @@ bool XmppClient::handleIq(const glooxwrapper::IQ& iq)
|
|||
const LobbyAuth* lobbyAuth = iq.findExtension<LobbyAuth>(EXTLOBBYAUTH);
|
||||
if (lobbyAuth)
|
||||
{
|
||||
LOGMESSAGE("XmppClient: Received lobby auth: %s from %s", lobbyAuth->m_Token.to_string(), iq.from().username());
|
||||
LOGMESSAGE("XmppClient: Received lobby auth: %s from %s", lobbyAuth->m_Token, iq.from().username());
|
||||
|
||||
glooxwrapper::IQ response(gloox::IQ::Result, iq.from(), iq.id());
|
||||
gloox::IQ response(gloox::IQ::Result, iq.from(), iq.id());
|
||||
m_client->send(response);
|
||||
|
||||
if (g_NetServer)
|
||||
g_NetServer->OnLobbyAuth(iq.from().username(), lobbyAuth->m_Token.to_string());
|
||||
g_NetServer->OnLobbyAuth(iq.from().username(), lobbyAuth->m_Token);
|
||||
else
|
||||
LOGMESSAGE("Received lobby authentication request, but not hosting currently!");
|
||||
}
|
||||
|
|
@ -974,7 +971,7 @@ bool XmppClient::handleIq(const glooxwrapper::IQ& iq)
|
|||
LOGMESSAGE("XmppClient: Received request for connection data from %s", iq.from().username());
|
||||
if (!g_NetServer)
|
||||
{
|
||||
glooxwrapper::IQ response(gloox::IQ::Result, iq.from(), iq.id());
|
||||
gloox::IQ response(gloox::IQ::Result, iq.from(), iq.id());
|
||||
ConnectionData* connectionData = new ConnectionData();
|
||||
connectionData->m_Error = "not_server";
|
||||
|
||||
|
|
@ -985,7 +982,7 @@ bool XmppClient::handleIq(const glooxwrapper::IQ& iq)
|
|||
}
|
||||
if (g_NetServer->IsBanned(iq.from().username()))
|
||||
{
|
||||
glooxwrapper::IQ response(gloox::IQ::Result, iq.from(), iq.id());
|
||||
gloox::IQ response(gloox::IQ::Result, iq.from(), iq.id());
|
||||
ConnectionData* connectionData = new ConnectionData();
|
||||
connectionData->m_Error = "banned";
|
||||
|
||||
|
|
@ -994,9 +991,9 @@ bool XmppClient::handleIq(const glooxwrapper::IQ& iq)
|
|||
m_client->send(response);
|
||||
return true;
|
||||
}
|
||||
if (!g_NetServer->CheckPasswordAndIncrement(iq.from().username(), cd->m_Password.to_string(), cd->m_ClientSalt.to_string()))
|
||||
if (!g_NetServer->CheckPasswordAndIncrement(iq.from().username(), cd->m_Password, cd->m_ClientSalt))
|
||||
{
|
||||
glooxwrapper::IQ response(gloox::IQ::Result, iq.from(), iq.id());
|
||||
gloox::IQ response(gloox::IQ::Result, iq.from(), iq.id());
|
||||
ConnectionData* connectionData = new ConnectionData();
|
||||
connectionData->m_Error = "invalid_password";
|
||||
|
||||
|
|
@ -1006,10 +1003,10 @@ bool XmppClient::handleIq(const glooxwrapper::IQ& iq)
|
|||
return true;
|
||||
}
|
||||
|
||||
glooxwrapper::IQ response(gloox::IQ::Result, iq.from(), iq.id());
|
||||
gloox::IQ response(gloox::IQ::Result, iq.from(), iq.id());
|
||||
ConnectionData* connectionData = new ConnectionData();
|
||||
|
||||
if (cd->m_IsLocalIP.to_string() == "0")
|
||||
if (cd->m_IsLocalIP == "0")
|
||||
{
|
||||
connectionData->m_Ip = g_NetServer->GetPublicIp();
|
||||
connectionData->m_Port = std::to_string(g_NetServer->GetPublicPort());
|
||||
|
|
@ -1037,7 +1034,7 @@ bool XmppClient::handleIq(const glooxwrapper::IQ& iq)
|
|||
|
||||
}
|
||||
else if (iq.subtype() == gloox::IQ::Error)
|
||||
CreateGUIMessage("system", "error", std::time(nullptr), "text", iq.error_error());
|
||||
CreateGUIMessage("system", "error", std::time(nullptr), "text", iq.error()->error());
|
||||
else
|
||||
{
|
||||
CreateGUIMessage("system", "error", std::time(nullptr), "text", wstring_from_utf8(g_L10n.Translate("unknown subtype (see logs)")));
|
||||
|
|
@ -1050,9 +1047,9 @@ bool XmppClient::handleIq(const glooxwrapper::IQ& iq)
|
|||
/**
|
||||
* Update local data when a user changes presence.
|
||||
*/
|
||||
void XmppClient::handleMUCParticipantPresence(glooxwrapper::MUCRoom& UNUSED(room), const glooxwrapper::MUCRoomParticipant participant, const glooxwrapper::Presence& presence)
|
||||
void XmppClient::handleMUCParticipantPresence(gloox::MUCRoom* UNUSED(room), const gloox::MUCRoomParticipant participant, const gloox::Presence& presence)
|
||||
{
|
||||
const glooxwrapper::string& nick = participant.nick->resource();
|
||||
const std::string& nick = participant.nick->resource();
|
||||
|
||||
if (presence.presence() == gloox::Presence::Unavailable)
|
||||
{
|
||||
|
|
@ -1169,9 +1166,9 @@ void XmppClient::handleMUCParticipantPresence(glooxwrapper::MUCRoom& UNUSED(room
|
|||
/**
|
||||
* Update local cache when subject changes.
|
||||
*/
|
||||
void XmppClient::handleMUCSubject(glooxwrapper::MUCRoom& UNUSED(room), const glooxwrapper::string& nick, const glooxwrapper::string& subject)
|
||||
void XmppClient::handleMUCSubject(gloox::MUCRoom* UNUSED(room), const std::string& nick, const std::string& subject)
|
||||
{
|
||||
m_Subject = wstring_from_utf8(subject.to_string());
|
||||
m_Subject = wstring_from_utf8(subject);
|
||||
|
||||
CreateGUIMessage(
|
||||
"chat",
|
||||
|
|
@ -1204,12 +1201,12 @@ void XmppClient::SetNick(const std::string& nick)
|
|||
*/
|
||||
std::string XmppClient::GetNick() const
|
||||
{
|
||||
return m_mucRoom->nick().to_string();
|
||||
return m_mucRoom->nick();
|
||||
}
|
||||
|
||||
std::string XmppClient::GetJID() const
|
||||
{
|
||||
return m_client->getJID().to_string();
|
||||
return m_client->getID();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -1289,7 +1286,7 @@ std::wstring XmppClient::GetRating(const std::string& nick)
|
|||
if (it == m_PlayerMap.end())
|
||||
return std::wstring();
|
||||
|
||||
return wstring_from_utf8(it->second.m_Rating.to_string());
|
||||
return wstring_from_utf8(it->second.m_Rating);
|
||||
}
|
||||
|
||||
/*****************************************************
|
||||
|
|
@ -1303,7 +1300,7 @@ std::wstring XmppClient::GetRating(const std::string& nick)
|
|||
*
|
||||
* @returns Seconds since the epoch.
|
||||
*/
|
||||
std::time_t XmppClient::ComputeTimestamp(const glooxwrapper::Message& msg)
|
||||
std::time_t XmppClient::ComputeTimestamp(const gloox::Message& msg)
|
||||
{
|
||||
// Only historic messages contain a timestamp!
|
||||
if (!msg.when())
|
||||
|
|
@ -1312,7 +1309,7 @@ std::time_t XmppClient::ComputeTimestamp(const glooxwrapper::Message& msg)
|
|||
// The locale is irrelevant, because the XMPP date format doesn't contain written month names
|
||||
for (const std::string& format : std::vector<std::string>{ "Y-M-d'T'H:m:sZ", "Y-M-d'T'H:m:s.SZ" })
|
||||
{
|
||||
UDate dateTime = g_L10n.ParseDateTime(msg.when()->stamp().to_string(), format, icu::Locale::getUS());
|
||||
UDate dateTime = g_L10n.ParseDateTime(msg.when()->stamp(), format, icu::Locale::getUS());
|
||||
if (dateTime)
|
||||
return dateTime / 1000.0;
|
||||
}
|
||||
|
|
@ -1505,20 +1502,51 @@ void XmppClient::SendStunEndpointToHost(const std::string& ip, u16 port, const s
|
|||
{
|
||||
DbgXMPP("SendStunEndpointToHost " << hostJIDStr);
|
||||
|
||||
glooxwrapper::JID hostJID(hostJIDStr);
|
||||
glooxwrapper::Jingle::Session session = m_sessionManager->createSession(hostJID);
|
||||
session.sessionInitiate(ip.c_str(), port);
|
||||
gloox::JID hostJID(hostJIDStr);
|
||||
gloox::Jingle::Session* session = m_sessionManager->createSession(hostJID, this);
|
||||
|
||||
gloox::Jingle::ICEUDP::CandidateList candidateList;
|
||||
|
||||
candidateList.push_back(gloox::Jingle::ICEUDP::Candidate{
|
||||
"1", // component_id,
|
||||
"1", // foundation
|
||||
"0", // candidate_generation
|
||||
"1", // candidate_id
|
||||
ip,
|
||||
"0", // network
|
||||
port,
|
||||
0, // priority
|
||||
"udp",
|
||||
"", // base_ip
|
||||
0, // base_port
|
||||
gloox::Jingle::ICEUDP::ServerReflexive});
|
||||
|
||||
// sessionInitiate deletes the new Content, and
|
||||
// the Plugin destructor inherited by Content frees the ICEUDP plugin.
|
||||
|
||||
gloox::Jingle::PluginList pluginList;
|
||||
pluginList.push_back(new gloox::Jingle::ICEUDP(/*local_pwd*/ "", /*local_ufrag*/ "", candidateList));
|
||||
|
||||
session->sessionInitiate(new gloox::Jingle::Content(std::string("game-data"), pluginList));
|
||||
}
|
||||
|
||||
void XmppClient::handleSessionAction(gloox::Jingle::Action action, glooxwrapper::Jingle::Session& session, const glooxwrapper::Jingle::Session::Jingle& jingle)
|
||||
void XmppClient::handleSessionAction(gloox::Jingle::Action action, gloox::Jingle::Session* session, const gloox::Jingle::Session::Jingle* jingle)
|
||||
{
|
||||
if (action == gloox::Jingle::SessionInitiate)
|
||||
handleSessionInitiation(session, jingle);
|
||||
}
|
||||
|
||||
void XmppClient::handleSessionInitiation(glooxwrapper::Jingle::Session& UNUSED(session), const glooxwrapper::Jingle::Session::Jingle& jingle)
|
||||
void XmppClient::handleSessionInitiation(gloox::Jingle::Session* UNUSED(session), const gloox::Jingle::Session::Jingle* jingle)
|
||||
{
|
||||
glooxwrapper::Jingle::ICEUDP::Candidate candidate = jingle.getCandidate();
|
||||
gloox::Jingle::ICEUDP::Candidate candidate{};
|
||||
|
||||
const gloox::Jingle::Content* content = static_cast<const gloox::Jingle::Content*>(jingle->plugins().front());
|
||||
if (content)
|
||||
{
|
||||
const gloox::Jingle::ICEUDP* iceUDP = static_cast<const gloox::Jingle::ICEUDP*>(content->findPlugin(gloox::Jingle::PluginICEUDP));
|
||||
if (iceUDP)
|
||||
candidate = iceUDP->candidates().front();
|
||||
}
|
||||
|
||||
if (candidate.ip.empty())
|
||||
{
|
||||
|
|
@ -1532,5 +1560,5 @@ void XmppClient::handleSessionInitiation(glooxwrapper::Jingle::Session& UNUSED(s
|
|||
return;
|
||||
}
|
||||
|
||||
g_NetServer->SendHolePunchingMessage(candidate.ip.to_string(), candidate.port);
|
||||
g_NetServer->SendHolePunchingMessage(candidate.ip, candidate.port);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@
|
|||
|
||||
#include "IXmppClient.h"
|
||||
|
||||
#include "glooxwrapper/glooxwrapper.h"
|
||||
#include "lib/external_libraries/gloox.h"
|
||||
|
||||
#include <ctime>
|
||||
#include <deque>
|
||||
|
|
@ -29,22 +29,16 @@
|
|||
|
||||
class ScriptRequest;
|
||||
|
||||
namespace glooxwrapper
|
||||
{
|
||||
class Client;
|
||||
struct CertInfo;
|
||||
}
|
||||
|
||||
class XmppClient : public IXmppClient, public glooxwrapper::ConnectionListener, public glooxwrapper::MUCRoomHandler, public glooxwrapper::IqHandler, public glooxwrapper::RegistrationHandler, public glooxwrapper::MessageHandler, public glooxwrapper::Jingle::SessionHandler
|
||||
class XmppClient : public IXmppClient, public gloox::ConnectionListener, public gloox::MUCRoomHandler, public gloox::IqHandler, public gloox::RegistrationHandler, public gloox::MessageHandler, public gloox::Jingle::SessionHandler, public gloox::LogHandler
|
||||
{
|
||||
NONCOPYABLE(XmppClient);
|
||||
|
||||
private:
|
||||
// Components
|
||||
glooxwrapper::Client* m_client;
|
||||
glooxwrapper::MUCRoom* m_mucRoom;
|
||||
glooxwrapper::Registration* m_registration;
|
||||
glooxwrapper::SessionManager* m_sessionManager;
|
||||
gloox::Client* m_client;
|
||||
gloox::MUCRoom* m_mucRoom;
|
||||
gloox::Registration* m_registration;
|
||||
gloox::Jingle::SessionManager* m_sessionManager;
|
||||
|
||||
// Account infos
|
||||
std::string m_username;
|
||||
|
|
@ -78,35 +72,35 @@ public:
|
|||
void TraceMember(JSTracer *trc);
|
||||
|
||||
// Network
|
||||
void connect();
|
||||
void disconnect();
|
||||
bool isConnected();
|
||||
void recv();
|
||||
void SendIqGetBoardList();
|
||||
void SendIqGetProfile(const std::string& player);
|
||||
void SendIqGameReport(const ScriptRequest& rq, JS::HandleValue data);
|
||||
void SendIqRegisterGame(const ScriptRequest& rq, JS::HandleValue data);
|
||||
void SendIqGetConnectionData(const std::string& jid, const std::string& password, const std::string& clientSalt, bool localIP);
|
||||
void SendIqUnregisterGame();
|
||||
void SendIqChangeStateGame(const std::string& nbp, const std::string& players);
|
||||
void SendIqLobbyAuth(const std::string& to, const std::string& token);
|
||||
void SetNick(const std::string& nick);
|
||||
std::string GetNick() const;
|
||||
std::string GetJID() const;
|
||||
void kick(const std::string& nick, const std::string& reason);
|
||||
void ban(const std::string& nick, const std::string& reason);
|
||||
void SetPresence(const std::string& presence);
|
||||
const char* GetPresence(const std::string& nickname);
|
||||
const char* GetRole(const std::string& nickname);
|
||||
std::wstring GetRating(const std::string& nickname);
|
||||
const std::wstring& GetSubject();
|
||||
void connect() override;
|
||||
void disconnect() override;
|
||||
bool isConnected() override;
|
||||
void recv() override;
|
||||
void SendIqGetBoardList() override;
|
||||
void SendIqGetProfile(const std::string& player) override;
|
||||
void SendIqGameReport(const ScriptRequest& rq, JS::HandleValue data) override;
|
||||
void SendIqRegisterGame(const ScriptRequest& rq, JS::HandleValue data) override;
|
||||
void SendIqGetConnectionData(const std::string& jid, const std::string& password, const std::string& clientSalt, bool localIP) override;
|
||||
void SendIqUnregisterGame() override;
|
||||
void SendIqChangeStateGame(const std::string& nbp, const std::string& players) override;
|
||||
void SendIqLobbyAuth(const std::string& to, const std::string& token) override;
|
||||
void SetNick(const std::string& nick) override;
|
||||
std::string GetNick() const override;
|
||||
std::string GetJID() const override;
|
||||
void kick(const std::string& nick, const std::string& reason) override;
|
||||
void ban(const std::string& nick, const std::string& reason) override;
|
||||
void SetPresence(const std::string& presence) override;
|
||||
const char* GetPresence(const std::string& nickname) override;
|
||||
const char* GetRole(const std::string& nickname) override;
|
||||
std::wstring GetRating(const std::string& nickname) override;
|
||||
const std::wstring& GetSubject() override;
|
||||
|
||||
JS::Value GUIGetPlayerList(const ScriptRequest& rq);
|
||||
JS::Value GUIGetGameList(const ScriptRequest& rq);
|
||||
JS::Value GUIGetBoardList(const ScriptRequest& rq);
|
||||
JS::Value GUIGetProfile(const ScriptRequest& rq);
|
||||
JS::Value GUIGetPlayerList(const ScriptRequest& rq) override;
|
||||
JS::Value GUIGetGameList(const ScriptRequest& rq) override;
|
||||
JS::Value GUIGetBoardList(const ScriptRequest& rq) override;
|
||||
JS::Value GUIGetProfile(const ScriptRequest& rq) override;
|
||||
|
||||
void SendStunEndpointToHost(const std::string& ip, u16 port, const std::string& hostJID);
|
||||
void SendStunEndpointToHost(const std::string& ip, u16 port, const std::string& hostJID) override;
|
||||
|
||||
/**
|
||||
* Convert gloox values to string or time.
|
||||
|
|
@ -117,52 +111,59 @@ public:
|
|||
static std::string RegistrationResultToString(gloox::RegistrationResult res);
|
||||
static std::string ConnectionErrorToString(gloox::ConnectionError err);
|
||||
static std::string CertificateErrorToString(gloox::CertStatus status);
|
||||
static std::time_t ComputeTimestamp(const glooxwrapper::Message& msg);
|
||||
static std::time_t ComputeTimestamp(const gloox::Message& msg);
|
||||
|
||||
protected:
|
||||
/* Xmpp handlers */
|
||||
/* MUC handlers */
|
||||
virtual void handleMUCParticipantPresence(glooxwrapper::MUCRoom& room, const glooxwrapper::MUCRoomParticipant, const glooxwrapper::Presence&);
|
||||
virtual void handleMUCError(glooxwrapper::MUCRoom& room, gloox::StanzaError);
|
||||
virtual void handleMUCMessage(glooxwrapper::MUCRoom& room, const glooxwrapper::Message& msg, bool priv);
|
||||
virtual void handleMUCSubject(glooxwrapper::MUCRoom& room, const glooxwrapper::string& nick, const glooxwrapper::string& subject);
|
||||
/* MUC handlers not supported by glooxwrapper */
|
||||
// virtual bool handleMUCRoomCreation(glooxwrapper::MUCRoom*) {return false;}
|
||||
// virtual void handleMUCInviteDecline(glooxwrapper::MUCRoom*, const glooxwrapper::JID&, const std::string&) {}
|
||||
// virtual void handleMUCInfo(glooxwrapper::MUCRoom*, int, const std::string&, const glooxwrapper::DataForm*) {}
|
||||
// virtual void handleMUCItems(glooxwrapper::MUCRoom*, const std::list<gloox::Disco::Item*, std::allocator<gloox::Disco::Item*> >&) {}
|
||||
void handleMUCParticipantPresence(gloox::MUCRoom* room, gloox::MUCRoomParticipant, const gloox::Presence&) override;
|
||||
void handleMUCError(gloox::MUCRoom* room, gloox::StanzaError) override;
|
||||
void handleMUCMessage(gloox::MUCRoom* room, const gloox::Message& msg, bool priv) override;
|
||||
void handleMUCSubject(gloox::MUCRoom* room, const std::string& nick, const std::string& subject) override;
|
||||
// Currently unused, provide noop implemtation for pure virtual functions.
|
||||
bool handleMUCRoomCreation(gloox::MUCRoom*) override { return false; }
|
||||
void handleMUCInviteDecline(gloox::MUCRoom*, const gloox::JID&, const std::string&) override {}
|
||||
void handleMUCInfo(gloox::MUCRoom*, int, const std::string&, const gloox::DataForm*) override {}
|
||||
void handleMUCItems(gloox::MUCRoom*, const std::list<gloox::Disco::Item*, std::allocator<gloox::Disco::Item*> >&) override {}
|
||||
|
||||
/* Log handler */
|
||||
virtual void handleLog(gloox::LogLevel level, gloox::LogArea area, const std::string& message);
|
||||
void handleLog(gloox::LogLevel level, gloox::LogArea area, const std::string& message) override;
|
||||
|
||||
/* ConnectionListener handlers*/
|
||||
virtual void onConnect();
|
||||
virtual void onDisconnect(gloox::ConnectionError e);
|
||||
virtual bool onTLSConnect(const glooxwrapper::CertInfo& info);
|
||||
void onConnect() override;
|
||||
void onDisconnect(gloox::ConnectionError e) override;
|
||||
bool onTLSConnect(const gloox::CertInfo& info) override;
|
||||
|
||||
/* Iq Handlers */
|
||||
virtual bool handleIq(const glooxwrapper::IQ& iq);
|
||||
virtual void handleIqID(const glooxwrapper::IQ&, int) {}
|
||||
bool handleIq(const gloox::IQ& iq) override;
|
||||
void handleIqID(const gloox::IQ&, int) override {}
|
||||
|
||||
/* Registration Handlers */
|
||||
virtual void handleRegistrationFields(const glooxwrapper::JID& /*from*/, int fields, glooxwrapper::string instructions );
|
||||
virtual void handleRegistrationResult(const glooxwrapper::JID& /*from*/, gloox::RegistrationResult result);
|
||||
virtual void handleAlreadyRegistered(const glooxwrapper::JID& /*from*/);
|
||||
virtual void handleDataForm(const glooxwrapper::JID& /*from*/, const glooxwrapper::DataForm& /*form*/);
|
||||
virtual void handleOOB(const glooxwrapper::JID& /*from*/, const glooxwrapper::OOB& oob);
|
||||
void handleRegistrationFields(const gloox::JID& /*from*/, int fields, std::string instructions ) override;
|
||||
#if GLOOXVERSION >= 0x010100
|
||||
void handleRegistrationResult(const gloox::JID& /*from*/, gloox::RegistrationResult result, const gloox::Error* /*error*/) override;
|
||||
#else
|
||||
void handleRegistrationResult(const gloox::JID& /*from*/, gloox::RegistrationResult result) override;
|
||||
#endif
|
||||
void handleAlreadyRegistered(const gloox::JID& /*from*/) override;
|
||||
void handleDataForm(const gloox::JID& /*from*/, const gloox::DataForm& /*form*/) override;
|
||||
void handleOOB(const gloox::JID& /*from*/, const gloox::OOB& oob) override;
|
||||
|
||||
/* Message Handler */
|
||||
virtual void handleMessage(const glooxwrapper::Message& msg, glooxwrapper::MessageSession* session);
|
||||
void handleMessage(const gloox::Message& msg, gloox::MessageSession* session) override;
|
||||
|
||||
/* Session Handler */
|
||||
virtual void handleSessionAction(gloox::Jingle::Action action, glooxwrapper::Jingle::Session& session, const glooxwrapper::Jingle::Session::Jingle& jingle);
|
||||
virtual void handleSessionInitiation(glooxwrapper::Jingle::Session& session, const glooxwrapper::Jingle::Session::Jingle& jingle);
|
||||
void handleSessionAction(gloox::Jingle::Action action, gloox::Jingle::Session* session, const gloox::Jingle::Session::Jingle* jingle) override;
|
||||
void handleSessionActionError(gloox::Jingle::Action /*action*/, gloox::Jingle::Session* /*session*/, const gloox::Error* /*error*/) override {}
|
||||
void handleIncomingSession(gloox::Jingle::Session* /*session*/) override {}
|
||||
private:
|
||||
void handleSessionInitiation(gloox::Jingle::Session* session, const gloox::Jingle::Session::Jingle* jingle);
|
||||
|
||||
public:
|
||||
JS::Value GuiPollNewMessages(const ScriptInterface& guiInterface);
|
||||
JS::Value GuiPollHistoricMessages(const ScriptInterface& guiInterface);
|
||||
bool GuiPollHasPlayerListUpdate();
|
||||
void SendMUCMessage(const std::string& message);
|
||||
JS::Value GuiPollNewMessages(const ScriptInterface& guiInterface) override;
|
||||
JS::Value GuiPollHistoricMessages(const ScriptInterface& guiInterface) override;
|
||||
bool GuiPollHasPlayerListUpdate() override;
|
||||
void SendMUCMessage(const std::string& message) override;
|
||||
|
||||
protected:
|
||||
template<typename... Args>
|
||||
|
|
@ -174,26 +175,26 @@ protected:
|
|||
|
||||
private:
|
||||
struct SPlayer {
|
||||
SPlayer(const gloox::Presence::PresenceType presence, const gloox::MUCRoomRole role, const glooxwrapper::string& rating)
|
||||
SPlayer(const gloox::Presence::PresenceType presence, const gloox::MUCRoomRole role, const std::string& rating)
|
||||
: m_Presence(presence), m_Role(role), m_Rating(rating)
|
||||
{
|
||||
}
|
||||
gloox::Presence::PresenceType m_Presence;
|
||||
gloox::MUCRoomRole m_Role;
|
||||
glooxwrapper::string m_Rating;
|
||||
std::string m_Rating;
|
||||
};
|
||||
using PlayerMap = std::map<glooxwrapper::string, SPlayer>;
|
||||
using PlayerMap = std::map<std::string, SPlayer>;
|
||||
|
||||
/// Map of players
|
||||
PlayerMap m_PlayerMap;
|
||||
/// Whether or not the playermap has changed since the last time the GUI checked.
|
||||
bool m_PlayerMapUpdate;
|
||||
/// List of games
|
||||
std::vector<const glooxwrapper::Tag*> m_GameList;
|
||||
std::vector<const gloox::Tag*> m_GameList;
|
||||
/// List of rankings
|
||||
std::vector<const glooxwrapper::Tag*> m_BoardList;
|
||||
std::vector<const gloox::Tag*> m_BoardList;
|
||||
/// Profile data
|
||||
std::vector<const glooxwrapper::Tag*> m_Profile;
|
||||
std::vector<const gloox::Tag*> m_Profile;
|
||||
/// ScriptInterface to root the values
|
||||
const ScriptInterface* m_ScriptInterface;
|
||||
/// Queue of messages for the GUI
|
||||
|
|
|
|||
|
|
@ -1,906 +0,0 @@
|
|||
/* Copyright (C) 2023 Wildfire Games.
|
||||
* This file is part of 0 A.D.
|
||||
*
|
||||
* 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
|
||||
* the Free Software Foundation, either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* 0 A.D. is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with 0 A.D. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "precompiled.h"
|
||||
|
||||
#include "glooxwrapper.h"
|
||||
|
||||
#include <gloox/connectionlistener.h>
|
||||
#include <gloox/error.h>
|
||||
#include <gloox/glooxversion.h>
|
||||
#include <gloox/messagehandler.h>
|
||||
|
||||
#if OS_WIN
|
||||
const std::string gloox::EmptyString = "";
|
||||
#endif
|
||||
|
||||
void* glooxwrapper::glooxwrapper_alloc(size_t size)
|
||||
{
|
||||
void* p = malloc(size);
|
||||
if (p == NULL)
|
||||
throw std::bad_alloc();
|
||||
return p;
|
||||
}
|
||||
|
||||
void glooxwrapper::glooxwrapper_free(void* p)
|
||||
{
|
||||
free(p);
|
||||
}
|
||||
|
||||
|
||||
namespace glooxwrapper
|
||||
{
|
||||
|
||||
class ConnectionListenerWrapper : public gloox::ConnectionListener
|
||||
{
|
||||
glooxwrapper::ConnectionListener* m_Wrapped;
|
||||
public:
|
||||
ConnectionListenerWrapper(glooxwrapper::ConnectionListener* wrapped) : m_Wrapped(wrapped) {}
|
||||
|
||||
virtual void onConnect()
|
||||
{
|
||||
m_Wrapped->onConnect();
|
||||
}
|
||||
|
||||
virtual void onDisconnect(gloox::ConnectionError e)
|
||||
{
|
||||
m_Wrapped->onDisconnect(e);
|
||||
}
|
||||
|
||||
virtual bool onTLSConnect(const gloox::CertInfo& info)
|
||||
{
|
||||
glooxwrapper::CertInfo infoWrapped;
|
||||
#define COPY(n) infoWrapped.n = info.n
|
||||
COPY(status);
|
||||
COPY(chain);
|
||||
COPY(issuer);
|
||||
COPY(server);
|
||||
COPY(date_from);
|
||||
COPY(date_to);
|
||||
COPY(protocol);
|
||||
COPY(cipher);
|
||||
COPY(mac);
|
||||
COPY(compression);
|
||||
#undef COPY
|
||||
return m_Wrapped->onTLSConnect(infoWrapped);
|
||||
}
|
||||
};
|
||||
|
||||
class IqHandlerWrapper : public gloox::IqHandler
|
||||
{
|
||||
glooxwrapper::IqHandler* m_Wrapped;
|
||||
public:
|
||||
IqHandlerWrapper(glooxwrapper::IqHandler* wrapped) : m_Wrapped(wrapped) {}
|
||||
|
||||
virtual bool handleIq(const gloox::IQ& iq)
|
||||
{
|
||||
glooxwrapper::IQ iqWrapper(iq);
|
||||
return m_Wrapped->handleIq(iqWrapper);
|
||||
}
|
||||
|
||||
virtual void handleIqID(const gloox::IQ& iq, int context)
|
||||
{
|
||||
glooxwrapper::IQ iqWrapper(iq);
|
||||
m_Wrapped->handleIqID(iqWrapper, context);
|
||||
}
|
||||
};
|
||||
|
||||
class MessageHandlerWrapper : public gloox::MessageHandler
|
||||
{
|
||||
glooxwrapper::MessageHandler* m_Wrapped;
|
||||
public:
|
||||
MessageHandlerWrapper(glooxwrapper::MessageHandler* wrapped) : m_Wrapped(wrapped) {}
|
||||
|
||||
virtual void handleMessage(const gloox::Message& msg, gloox::MessageSession* UNUSED(session))
|
||||
{
|
||||
/* MessageSession not supported */
|
||||
glooxwrapper::Message msgWrapper(const_cast<gloox::Message*>(&msg), false);
|
||||
m_Wrapped->handleMessage(msgWrapper, NULL);
|
||||
}
|
||||
};
|
||||
|
||||
class MUCRoomHandlerWrapper : public gloox::MUCRoomHandler
|
||||
{
|
||||
glooxwrapper::MUCRoomHandler* m_Wrapped;
|
||||
public:
|
||||
MUCRoomHandlerWrapper(glooxwrapper::MUCRoomHandler* wrapped) : m_Wrapped(wrapped) {}
|
||||
|
||||
virtual ~MUCRoomHandlerWrapper() {}
|
||||
|
||||
virtual void handleMUCParticipantPresence(gloox::MUCRoom* room, const gloox::MUCRoomParticipant participant, const gloox::Presence& presence)
|
||||
{
|
||||
glooxwrapper::MUCRoom roomWrapper(room, false);
|
||||
glooxwrapper::MUCRoomParticipant part;
|
||||
glooxwrapper::JID nick(*participant.nick);
|
||||
glooxwrapper::JID jid(*participant.jid);
|
||||
glooxwrapper::JID actor(*participant.actor);
|
||||
glooxwrapper::JID alternate(*participant.alternate);
|
||||
part.nick = participant.nick ? &nick : NULL;
|
||||
part.affiliation = participant.affiliation;
|
||||
part.role = participant.role;
|
||||
part.jid = participant.jid ? &jid : NULL;
|
||||
part.flags = participant.flags;
|
||||
part.reason = participant.reason;
|
||||
part.actor = participant.actor ? &actor : NULL;
|
||||
part.newNick = participant.newNick;
|
||||
part.status = participant.status;
|
||||
part.alternate = participant.alternate ? &alternate : NULL;
|
||||
|
||||
m_Wrapped->handleMUCParticipantPresence(roomWrapper, part, glooxwrapper::Presence(presence.presence()));
|
||||
|
||||
/* gloox 1.0 leaks some JIDs (fixed in 1.0.1), so clean them up */
|
||||
#if GLOOXVERSION == 0x10000
|
||||
delete participant.jid;
|
||||
delete participant.actor;
|
||||
delete participant.alternate;
|
||||
#endif
|
||||
}
|
||||
|
||||
virtual void handleMUCMessage(gloox::MUCRoom* room, const gloox::Message& msg, bool priv)
|
||||
{
|
||||
glooxwrapper::MUCRoom roomWrapper(room, false);
|
||||
glooxwrapper::Message msgWrapper(const_cast<gloox::Message*>(&msg), false);
|
||||
m_Wrapped->handleMUCMessage(roomWrapper, msgWrapper, priv);
|
||||
}
|
||||
|
||||
virtual bool handleMUCRoomCreation(gloox::MUCRoom* UNUSED(room))
|
||||
{
|
||||
/* Not supported */
|
||||
return false;
|
||||
}
|
||||
|
||||
virtual void handleMUCSubject(gloox::MUCRoom* room, const std::string& nick, const std::string& subject)
|
||||
{
|
||||
glooxwrapper::MUCRoom roomWrapper(room, false);
|
||||
m_Wrapped->handleMUCSubject(roomWrapper, nick, subject);
|
||||
}
|
||||
|
||||
virtual void handleMUCInviteDecline(gloox::MUCRoom* UNUSED(room), const gloox::JID& UNUSED(invitee), const std::string& UNUSED(reason))
|
||||
{
|
||||
/* Not supported */
|
||||
}
|
||||
|
||||
virtual void handleMUCError(gloox::MUCRoom* room, gloox::StanzaError error)
|
||||
{
|
||||
glooxwrapper::MUCRoom roomWrapper(room, false);
|
||||
m_Wrapped->handleMUCError(roomWrapper, error);
|
||||
}
|
||||
|
||||
virtual void handleMUCInfo(gloox::MUCRoom* UNUSED(room), int UNUSED(features), const std::string& UNUSED(name), const gloox::DataForm* UNUSED(infoForm))
|
||||
{
|
||||
/* Not supported */
|
||||
}
|
||||
|
||||
virtual void handleMUCItems(gloox::MUCRoom* UNUSED(room), const gloox::Disco::ItemList& UNUSED(items))
|
||||
{
|
||||
/* Not supported */
|
||||
}
|
||||
};
|
||||
|
||||
class RegistrationHandlerWrapper : public gloox::RegistrationHandler
|
||||
{
|
||||
glooxwrapper::RegistrationHandler* m_Wrapped;
|
||||
public:
|
||||
RegistrationHandlerWrapper(glooxwrapper::RegistrationHandler* wrapped) : m_Wrapped(wrapped) {}
|
||||
|
||||
virtual void handleRegistrationFields(const gloox::JID& from, int fields, std::string instructions)
|
||||
{
|
||||
glooxwrapper::JID fromWrapped(from);
|
||||
m_Wrapped->handleRegistrationFields(fromWrapped, fields, instructions);
|
||||
}
|
||||
|
||||
virtual void handleAlreadyRegistered(const gloox::JID& from)
|
||||
{
|
||||
glooxwrapper::JID fromWrapped(from);
|
||||
m_Wrapped->handleAlreadyRegistered(fromWrapped);
|
||||
}
|
||||
|
||||
#if OS_WIN
|
||||
virtual void handleRegistrationResult(const gloox::JID& from, gloox::RegistrationResult regResult, const gloox::Error* UNUSED(error))
|
||||
#else
|
||||
virtual void handleRegistrationResult(const gloox::JID& from, gloox::RegistrationResult regResult)
|
||||
#endif
|
||||
{
|
||||
glooxwrapper::JID fromWrapped(from);
|
||||
m_Wrapped->handleRegistrationResult(fromWrapped, regResult);
|
||||
}
|
||||
|
||||
virtual void handleDataForm(const gloox::JID& UNUSED(from), const gloox::DataForm& UNUSED(form))
|
||||
{
|
||||
/* DataForm not supported */
|
||||
}
|
||||
|
||||
virtual void handleOOB(const gloox::JID& UNUSED(from), const gloox::OOB& UNUSED(oob))
|
||||
{
|
||||
/* OOB not supported */
|
||||
}
|
||||
};
|
||||
|
||||
class StanzaExtensionWrapper : public gloox::StanzaExtension
|
||||
{
|
||||
public:
|
||||
const glooxwrapper::StanzaExtension* m_Wrapped;
|
||||
bool m_Owned;
|
||||
std::string m_FilterString;
|
||||
|
||||
StanzaExtensionWrapper(const glooxwrapper::StanzaExtension* wrapped, bool owned) :
|
||||
gloox::StanzaExtension(wrapped->extensionType()), m_Wrapped(wrapped), m_Owned(owned)
|
||||
{
|
||||
m_FilterString = m_Wrapped->filterString().to_string();
|
||||
}
|
||||
|
||||
~StanzaExtensionWrapper()
|
||||
{
|
||||
if (m_Owned)
|
||||
delete m_Wrapped;
|
||||
}
|
||||
|
||||
virtual const std::string& filterString() const
|
||||
{
|
||||
return m_FilterString;
|
||||
}
|
||||
|
||||
virtual gloox::StanzaExtension* newInstance(const gloox::Tag* tag) const
|
||||
{
|
||||
glooxwrapper::Tag* tagWrapper = glooxwrapper::Tag::allocate(const_cast<gloox::Tag*>(tag), false);
|
||||
gloox::StanzaExtension* ret = new StanzaExtensionWrapper(m_Wrapped->newInstance(tagWrapper), true);
|
||||
glooxwrapper::Tag::free(tagWrapper);
|
||||
return ret;
|
||||
}
|
||||
|
||||
virtual gloox::Tag* tag() const
|
||||
{
|
||||
glooxwrapper::Tag* wrapper = m_Wrapped->tag();
|
||||
gloox::Tag* ret = wrapper->stealWrapped();
|
||||
glooxwrapper::Tag::free(wrapper);
|
||||
return ret;
|
||||
}
|
||||
|
||||
virtual gloox::StanzaExtension* clone() const
|
||||
{
|
||||
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) {}
|
||||
|
||||
~SessionHandlerWrapper()
|
||||
{
|
||||
if (m_Owned)
|
||||
delete m_Wrapped;
|
||||
}
|
||||
|
||||
virtual void handleSessionAction(gloox::Jingle::Action action, gloox::Jingle::Session* session, const gloox::Jingle::Session::Jingle* jingle)
|
||||
{
|
||||
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))
|
||||
{
|
||||
}
|
||||
|
||||
virtual void handleIncomingSession(gloox::Jingle::Session* UNUSED(session))
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
class ClientImpl
|
||||
{
|
||||
public:
|
||||
// List of registered callback wrappers, to get deleted when Client is deleted
|
||||
std::list<std::shared_ptr<gloox::ConnectionListener>> m_ConnectionListeners;
|
||||
std::list<std::shared_ptr<gloox::MessageHandler>> m_MessageHandlers;
|
||||
std::list<std::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";
|
||||
|
||||
} // namespace glooxwrapper
|
||||
|
||||
|
||||
glooxwrapper::Client::Client(const string& server)
|
||||
{
|
||||
m_Wrapped = new gloox::Client(server.to_string());
|
||||
m_DiscoWrapper = new glooxwrapper::Disco(m_Wrapped->disco());
|
||||
m_Impl = new ClientImpl;
|
||||
}
|
||||
|
||||
glooxwrapper::Client::Client(const JID& jid, const string& password, int port)
|
||||
{
|
||||
m_Wrapped = new gloox::Client(jid.getWrapped(), password.to_string(), port);
|
||||
m_DiscoWrapper = new glooxwrapper::Disco(m_Wrapped->disco());
|
||||
m_Impl = new ClientImpl;
|
||||
}
|
||||
|
||||
glooxwrapper::Client::~Client()
|
||||
{
|
||||
delete m_Wrapped;
|
||||
delete m_DiscoWrapper;
|
||||
delete m_Impl;
|
||||
}
|
||||
|
||||
bool glooxwrapper::Client::connect(bool block)
|
||||
{
|
||||
return m_Wrapped->connect(block);
|
||||
}
|
||||
|
||||
gloox::ConnectionError glooxwrapper::Client::recv(int timeout)
|
||||
{
|
||||
return m_Wrapped->recv(timeout);
|
||||
}
|
||||
|
||||
const glooxwrapper::string glooxwrapper::Client::getID() const
|
||||
{
|
||||
return m_Wrapped->getID();
|
||||
}
|
||||
|
||||
const glooxwrapper::string glooxwrapper::Client::getJID() const
|
||||
{
|
||||
return m_Wrapped->jid().full();
|
||||
}
|
||||
|
||||
void glooxwrapper::Client::send(const IQ& iq)
|
||||
{
|
||||
m_Wrapped->send(iq.getWrapped());
|
||||
}
|
||||
|
||||
void glooxwrapper::Client::setTls(gloox::TLSPolicy tls)
|
||||
{
|
||||
m_Wrapped->setTls(tls);
|
||||
}
|
||||
|
||||
void glooxwrapper::Client::setCompression(bool compression)
|
||||
{
|
||||
m_Wrapped->setCompression(compression);
|
||||
}
|
||||
|
||||
void glooxwrapper::Client::setSASLMechanisms(int mechanisms)
|
||||
{
|
||||
m_Wrapped->setSASLMechanisms(mechanisms);
|
||||
}
|
||||
|
||||
void glooxwrapper::Client::disconnect()
|
||||
{
|
||||
m_Wrapped->disconnect();
|
||||
}
|
||||
|
||||
void glooxwrapper::Client::registerStanzaExtension(glooxwrapper::StanzaExtension* ext)
|
||||
{
|
||||
// ~StanzaExtensionFactory() deletes this new StanzaExtensionWrapper
|
||||
m_Wrapped->registerStanzaExtension(new StanzaExtensionWrapper(ext, true));
|
||||
}
|
||||
|
||||
void glooxwrapper::Client::registerConnectionListener(glooxwrapper::ConnectionListener* hnd)
|
||||
{
|
||||
gloox::ConnectionListener* listener = new ConnectionListenerWrapper(hnd);
|
||||
m_Wrapped->registerConnectionListener(listener);
|
||||
m_Impl->m_ConnectionListeners.push_back(std::shared_ptr<gloox::ConnectionListener>(listener));
|
||||
}
|
||||
|
||||
void glooxwrapper::Client::registerMessageHandler(glooxwrapper::MessageHandler* hnd)
|
||||
{
|
||||
gloox::MessageHandler* handler = new MessageHandlerWrapper(hnd);
|
||||
m_Wrapped->registerMessageHandler(handler);
|
||||
m_Impl->m_MessageHandlers.push_back(std::shared_ptr<gloox::MessageHandler>(handler));
|
||||
}
|
||||
|
||||
void glooxwrapper::Client::registerIqHandler(glooxwrapper::IqHandler* ih, int exttype)
|
||||
{
|
||||
gloox::IqHandler* handler = new IqHandlerWrapper(ih);
|
||||
m_Wrapped->registerIqHandler(handler, exttype);
|
||||
m_Impl->m_IqHandlers.push_back(std::shared_ptr<gloox::IqHandler>(handler));
|
||||
}
|
||||
|
||||
bool glooxwrapper::Client::removePresenceExtension(int type)
|
||||
{
|
||||
return m_Wrapped->removePresenceExtension(type);
|
||||
}
|
||||
|
||||
void glooxwrapper::Client::setPresence(gloox::Presence::PresenceType pres, int priority, const string& status)
|
||||
{
|
||||
m_Wrapped->setPresence(pres, priority, status.to_string());
|
||||
}
|
||||
|
||||
|
||||
glooxwrapper::DelayedDelivery::DelayedDelivery(const gloox::DelayedDelivery* wrapped)
|
||||
{
|
||||
m_Wrapped = wrapped;
|
||||
}
|
||||
|
||||
const glooxwrapper::string glooxwrapper::DelayedDelivery::stamp() const
|
||||
{
|
||||
return m_Wrapped->stamp();
|
||||
}
|
||||
|
||||
|
||||
glooxwrapper::Disco::Disco(gloox::Disco* wrapped)
|
||||
{
|
||||
m_Wrapped = wrapped;
|
||||
}
|
||||
|
||||
void glooxwrapper::Disco::setVersion(const string& name, const string& version, const string& os)
|
||||
{
|
||||
m_Wrapped->setVersion(name.to_string(), version.to_string(), os.to_string());
|
||||
}
|
||||
|
||||
void glooxwrapper::Disco::setIdentity(const string& category, const string& type, const string& name)
|
||||
{
|
||||
m_Wrapped->setIdentity(category.to_string(), type.to_string(), name.to_string());
|
||||
}
|
||||
|
||||
|
||||
glooxwrapper::IQ::IQ(gloox::IQ::IqType type, const JID& to, const string& id)
|
||||
{
|
||||
m_Wrapped = new gloox::IQ(type, to.getWrapped(), id.to_string());
|
||||
m_Owned = true;
|
||||
}
|
||||
|
||||
glooxwrapper::IQ::~IQ()
|
||||
{
|
||||
if (m_Owned)
|
||||
delete m_Wrapped;
|
||||
}
|
||||
|
||||
void glooxwrapper::IQ::addExtension(const glooxwrapper::StanzaExtension* se)
|
||||
{
|
||||
m_Wrapped->addExtension(new StanzaExtensionWrapper(se, true));
|
||||
}
|
||||
|
||||
const glooxwrapper::StanzaExtension* glooxwrapper::IQ::findExtension(int type) const
|
||||
{
|
||||
const gloox::StanzaExtension* ext = m_Wrapped->findExtension(type);
|
||||
if (!ext)
|
||||
return NULL;
|
||||
return static_cast<const StanzaExtensionWrapper*>(ext)->m_Wrapped;
|
||||
}
|
||||
|
||||
gloox::StanzaError glooxwrapper::IQ::error_error() const
|
||||
{
|
||||
const gloox::Error* error = m_Wrapped->error();
|
||||
if (!error)
|
||||
return gloox::StanzaErrorInternalServerError;
|
||||
return error->error();
|
||||
}
|
||||
|
||||
glooxwrapper::Tag* glooxwrapper::IQ::tag() const
|
||||
{
|
||||
return Tag::allocate(m_Wrapped->tag(), true);
|
||||
}
|
||||
|
||||
gloox::IQ::IqType glooxwrapper::IQ::subtype() const
|
||||
{
|
||||
return m_Wrapped->subtype();
|
||||
}
|
||||
|
||||
const glooxwrapper::string glooxwrapper::IQ::id() const
|
||||
{
|
||||
return m_Wrapped->id();
|
||||
}
|
||||
|
||||
const gloox::JID& glooxwrapper::IQ::from() const
|
||||
{
|
||||
return m_Wrapped->from();
|
||||
}
|
||||
|
||||
glooxwrapper::JID::JID()
|
||||
{
|
||||
m_Wrapped = new gloox::JID();
|
||||
m_Owned = true;
|
||||
}
|
||||
|
||||
glooxwrapper::JID::JID(const glooxwrapper::string& jid)
|
||||
{
|
||||
m_Wrapped = new gloox::JID(jid.to_string());
|
||||
m_Owned = true;
|
||||
}
|
||||
|
||||
void glooxwrapper::JID::init(const char* data, size_t len)
|
||||
{
|
||||
m_Wrapped = new gloox::JID(std::string(data, data+len));
|
||||
m_Owned = true;
|
||||
}
|
||||
|
||||
glooxwrapper::JID::~JID()
|
||||
{
|
||||
if (m_Owned)
|
||||
delete m_Wrapped;
|
||||
}
|
||||
|
||||
glooxwrapper::string glooxwrapper::JID::username() const
|
||||
{
|
||||
return m_Wrapped->username();
|
||||
}
|
||||
|
||||
glooxwrapper::string glooxwrapper::JID::resource() const
|
||||
{
|
||||
return m_Wrapped->resource();
|
||||
};
|
||||
|
||||
|
||||
glooxwrapper::Message::Message(gloox::Message* wrapped, bool owned)
|
||||
: m_Wrapped(wrapped),
|
||||
m_Owned(owned),
|
||||
m_From(m_Wrapped->from()),
|
||||
m_DelayedDelivery(m_Wrapped->when() ? new glooxwrapper::DelayedDelivery(m_Wrapped->when()) : nullptr)
|
||||
{
|
||||
}
|
||||
|
||||
glooxwrapper::Message::~Message()
|
||||
{
|
||||
if (m_Owned)
|
||||
delete m_Wrapped;
|
||||
delete m_DelayedDelivery;
|
||||
}
|
||||
|
||||
gloox::Message::MessageType glooxwrapper::Message::subtype() const
|
||||
{
|
||||
return m_Wrapped->subtype();
|
||||
}
|
||||
|
||||
const glooxwrapper::JID& glooxwrapper::Message::from() const
|
||||
{
|
||||
return m_From;
|
||||
}
|
||||
|
||||
glooxwrapper::string glooxwrapper::Message::body() const
|
||||
{
|
||||
return m_Wrapped->body();
|
||||
}
|
||||
|
||||
glooxwrapper::string glooxwrapper::Message::subject(const string& lang) const
|
||||
{
|
||||
return m_Wrapped->subject(lang.to_string());
|
||||
}
|
||||
|
||||
glooxwrapper::string glooxwrapper::Message::thread() const
|
||||
{
|
||||
return m_Wrapped->thread();
|
||||
}
|
||||
|
||||
const glooxwrapper::DelayedDelivery* glooxwrapper::Message::when() const
|
||||
{
|
||||
return m_DelayedDelivery;
|
||||
}
|
||||
|
||||
glooxwrapper::MUCRoom::MUCRoom(gloox::MUCRoom* room, bool owned)
|
||||
: m_Wrapped(room), m_Owned(owned), m_HandlerWrapper(nullptr)
|
||||
{
|
||||
}
|
||||
|
||||
glooxwrapper::MUCRoom::MUCRoom(Client* parent, const JID& nick, MUCRoomHandler* mrh, MUCRoomConfigHandler* UNUSED(mrch))
|
||||
{
|
||||
m_HandlerWrapper = new MUCRoomHandlerWrapper(mrh);
|
||||
m_Wrapped = new gloox::MUCRoom(parent ? parent->getWrapped() : NULL, nick.getWrapped(), m_HandlerWrapper);
|
||||
m_Owned = true;
|
||||
}
|
||||
|
||||
glooxwrapper::MUCRoom::~MUCRoom()
|
||||
{
|
||||
if (m_Owned)
|
||||
delete m_Wrapped;
|
||||
|
||||
delete m_HandlerWrapper;
|
||||
}
|
||||
|
||||
const glooxwrapper::string glooxwrapper::MUCRoom::nick() const
|
||||
{
|
||||
return m_Wrapped->nick();
|
||||
}
|
||||
|
||||
const glooxwrapper::string glooxwrapper::MUCRoom::name() const
|
||||
{
|
||||
return m_Wrapped->name();
|
||||
}
|
||||
|
||||
const glooxwrapper::string glooxwrapper::MUCRoom::service() const
|
||||
{
|
||||
return m_Wrapped->service();
|
||||
}
|
||||
|
||||
void glooxwrapper::MUCRoom::join(gloox::Presence::PresenceType type, const string& status, int priority)
|
||||
{
|
||||
m_Wrapped->join(type, status.to_string(), priority);
|
||||
}
|
||||
|
||||
void glooxwrapper::MUCRoom::leave(const string& msg)
|
||||
{
|
||||
m_Wrapped->leave(msg.to_string());
|
||||
}
|
||||
|
||||
void glooxwrapper::MUCRoom::send(const string& message)
|
||||
{
|
||||
m_Wrapped->send(message.to_string());
|
||||
}
|
||||
|
||||
void glooxwrapper::MUCRoom::setNick(const string& nick)
|
||||
{
|
||||
m_Wrapped->setNick(nick.to_string());
|
||||
}
|
||||
|
||||
void glooxwrapper::MUCRoom::setPresence(gloox::Presence::PresenceType presence, const string& msg)
|
||||
{
|
||||
m_Wrapped->setPresence(presence, msg.to_string());
|
||||
}
|
||||
|
||||
void glooxwrapper::MUCRoom::setRequestHistory(int value, gloox::MUCRoom::HistoryRequestType type)
|
||||
{
|
||||
m_Wrapped->setRequestHistory(value, type);
|
||||
}
|
||||
|
||||
void glooxwrapper::MUCRoom::kick(const string& nick, const string& reason)
|
||||
{
|
||||
m_Wrapped->kick(nick.to_string(), reason.to_string());
|
||||
}
|
||||
|
||||
void glooxwrapper::MUCRoom::ban(const string& nick, const string& reason)
|
||||
{
|
||||
m_Wrapped->ban(nick.to_string(), reason.to_string());
|
||||
}
|
||||
|
||||
|
||||
glooxwrapper::Registration::Registration(Client* parent)
|
||||
{
|
||||
m_Wrapped = new gloox::Registration(parent->getWrapped());
|
||||
}
|
||||
|
||||
glooxwrapper::Registration::~Registration()
|
||||
{
|
||||
delete m_Wrapped;
|
||||
}
|
||||
|
||||
void glooxwrapper::Registration::fetchRegistrationFields()
|
||||
{
|
||||
m_Wrapped->fetchRegistrationFields();
|
||||
}
|
||||
|
||||
bool glooxwrapper::Registration::createAccount(int fields, const glooxwrapper::RegistrationFields& values)
|
||||
{
|
||||
gloox::RegistrationFields valuesUnwrapped;
|
||||
#define COPY(n) valuesUnwrapped.n = values.n.to_string()
|
||||
COPY(username);
|
||||
COPY(nick);
|
||||
COPY(password);
|
||||
COPY(name);
|
||||
COPY(first);
|
||||
COPY(last);
|
||||
COPY(email);
|
||||
COPY(address);
|
||||
COPY(city);
|
||||
COPY(state);
|
||||
COPY(zip);
|
||||
COPY(phone);
|
||||
COPY(url);
|
||||
COPY(date);
|
||||
#if !OS_WIN
|
||||
COPY(misc);
|
||||
COPY(text);
|
||||
#endif
|
||||
#undef COPY
|
||||
return m_Wrapped->createAccount(fields, valuesUnwrapped);
|
||||
}
|
||||
|
||||
void glooxwrapper::Registration::registerRegistrationHandler(RegistrationHandler* rh)
|
||||
{
|
||||
gloox::RegistrationHandler* handler = new RegistrationHandlerWrapper(rh);
|
||||
m_Wrapped->registerRegistrationHandler(handler);
|
||||
m_RegistrationHandlers.push_back(std::shared_ptr<gloox::RegistrationHandler>(handler));
|
||||
}
|
||||
|
||||
|
||||
glooxwrapper::Tag::Tag(const string& name)
|
||||
{
|
||||
m_Wrapped = new gloox::Tag(name.to_string());
|
||||
m_Owned = true;
|
||||
}
|
||||
|
||||
glooxwrapper::Tag::Tag(const string& name, const string& cdata)
|
||||
{
|
||||
m_Wrapped = new gloox::Tag(name.to_string(), cdata.to_string());
|
||||
m_Owned = true;
|
||||
}
|
||||
|
||||
glooxwrapper::Tag::~Tag()
|
||||
{
|
||||
if (m_Owned)
|
||||
delete m_Wrapped;
|
||||
}
|
||||
|
||||
glooxwrapper::Tag* glooxwrapper::Tag::allocate(const string& name)
|
||||
{
|
||||
return new glooxwrapper::Tag(name);
|
||||
}
|
||||
|
||||
glooxwrapper::Tag* glooxwrapper::Tag::allocate(const string& name, const string& cdata)
|
||||
{
|
||||
return new glooxwrapper::Tag(name, cdata);
|
||||
}
|
||||
|
||||
glooxwrapper::Tag* glooxwrapper::Tag::allocate(gloox::Tag* wrapped, bool owned)
|
||||
{
|
||||
return new glooxwrapper::Tag(wrapped, owned);
|
||||
}
|
||||
|
||||
void glooxwrapper::Tag::free(const glooxwrapper::Tag* tag)
|
||||
{
|
||||
delete tag;
|
||||
}
|
||||
|
||||
bool glooxwrapper::Tag::addAttribute(const string& name, const string& value)
|
||||
{
|
||||
return m_Wrapped->addAttribute(name.to_string(), value.to_string());
|
||||
}
|
||||
|
||||
glooxwrapper::string glooxwrapper::Tag::findAttribute(const string& name) const
|
||||
{
|
||||
return m_Wrapped->findAttribute(name.to_string());
|
||||
}
|
||||
|
||||
glooxwrapper::Tag* glooxwrapper::Tag::clone() const
|
||||
{
|
||||
return new glooxwrapper::Tag(m_Wrapped->clone(), true);
|
||||
}
|
||||
|
||||
glooxwrapper::string glooxwrapper::Tag::xmlns() const
|
||||
{
|
||||
return m_Wrapped->xmlns();
|
||||
}
|
||||
|
||||
bool glooxwrapper::Tag::setXmlns(const string& xmlns)
|
||||
{
|
||||
return m_Wrapped->setXmlns(xmlns.to_string());
|
||||
}
|
||||
|
||||
glooxwrapper::string glooxwrapper::Tag::xml() const
|
||||
{
|
||||
return m_Wrapped->xml();
|
||||
}
|
||||
|
||||
void glooxwrapper::Tag::addChild(Tag* child)
|
||||
{
|
||||
m_Wrapped->addChild(child->stealWrapped());
|
||||
Tag::free(child);
|
||||
}
|
||||
|
||||
glooxwrapper::string glooxwrapper::Tag::name() const
|
||||
{
|
||||
return m_Wrapped->name();
|
||||
}
|
||||
|
||||
glooxwrapper::string glooxwrapper::Tag::cdata() const
|
||||
{
|
||||
return m_Wrapped->cdata();
|
||||
}
|
||||
|
||||
const glooxwrapper::Tag* glooxwrapper::Tag::findTag_clone(const string& expression) const
|
||||
{
|
||||
const gloox::Tag* tag = m_Wrapped->findTag(expression.to_string());
|
||||
if (!tag)
|
||||
return NULL;
|
||||
return new glooxwrapper::Tag(const_cast<gloox::Tag*>(tag), false);
|
||||
}
|
||||
|
||||
glooxwrapper::ConstTagList glooxwrapper::Tag::findTagList_clone(const string& expression) const
|
||||
{
|
||||
glooxwrapper::ConstTagList tagListWrapper;
|
||||
for (const gloox::Tag* const& t : m_Wrapped->findTagList(expression.to_string()))
|
||||
tagListWrapper.push_back(new glooxwrapper::Tag(const_cast<gloox::Tag*>(t), false));
|
||||
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::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)
|
||||
return glooxwrapper::Jingle::ICEUDP::Candidate();
|
||||
|
||||
const gloox::Jingle::ICEUDP* iceUDP = static_cast<const gloox::Jingle::ICEUDP*>(content->findPlugin(gloox::Jingle::PluginICEUDP));
|
||||
if (!iceUDP)
|
||||
return glooxwrapper::Jingle::ICEUDP::Candidate();
|
||||
|
||||
gloox::Jingle::ICEUDP::Candidate glooxCandidate = iceUDP->candidates().front();
|
||||
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(const char* ipStr, u16 port)
|
||||
{
|
||||
gloox::Jingle::ICEUDP::CandidateList candidateList;
|
||||
|
||||
candidateList.push_back(gloox::Jingle::ICEUDP::Candidate
|
||||
{
|
||||
"1", // component_id,
|
||||
"1", // foundation
|
||||
"0", // andidate_generation
|
||||
"1", // candidate_id
|
||||
ipStr,
|
||||
"0", // network
|
||||
port,
|
||||
0, // priotiry
|
||||
"udp",
|
||||
"", // base_ip
|
||||
0, // base_port
|
||||
gloox::Jingle::ICEUDP::ServerReflexive
|
||||
});
|
||||
|
||||
// sessionInitiate deletes the new Content, and
|
||||
// the Plugin destructor inherited by Content frees the ICEUDP plugin.
|
||||
|
||||
gloox::Jingle::PluginList 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));
|
||||
}
|
||||
|
||||
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()
|
||||
{
|
||||
// This calls m_factory.registerPlugin (see jinglesessionmanager.cpp), hence
|
||||
// ~PluginFactory() will delete these new plugin templates.
|
||||
m_Wrapped->registerPlugin(new gloox::Jingle::Content());
|
||||
m_Wrapped->registerPlugin(new gloox::Jingle::ICEUDP());
|
||||
}
|
||||
|
||||
glooxwrapper::Jingle::Session glooxwrapper::SessionManager::createSession(const JID& callee)
|
||||
{
|
||||
// The wrapped gloox SessionManager keeps track of this session and deletes it on ~SessionManager().
|
||||
gloox::Jingle::Session* glooxSession = m_Wrapped->createSession(callee.getWrapped(), m_HandlerWrapper);
|
||||
|
||||
// Hence the glooxwrapper::Jingle::Session may not own the gloox::Jingle::Session.
|
||||
return glooxwrapper::Jingle::Session(glooxSession, false);
|
||||
}
|
||||
|
|
@ -1,705 +0,0 @@
|
|||
/* Copyright (C) 2023 Wildfire Games.
|
||||
* This file is part of 0 A.D.
|
||||
*
|
||||
* 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
|
||||
* the Free Software Foundation, either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* 0 A.D. is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with 0 A.D. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef INCLUDED_GLOOXWRAPPER_H
|
||||
#define INCLUDED_GLOOXWRAPPER_H
|
||||
|
||||
/*
|
||||
|
||||
The gloox API uses various STL types (std::string, std::list, etc), and
|
||||
it has functions that acquire/release ownership of objects and expect the
|
||||
library's user's 'new'/'delete' functions to be compatible with the library's.
|
||||
|
||||
These assumptions are invalid when the game and library are built with
|
||||
different compiler versions (or the same version with different build flags):
|
||||
the STL types have different layouts, and new/delete can use different heaps.
|
||||
|
||||
We want to let people build the game on Windows with any compiler version
|
||||
(any supported Visual Studio version, and debug vs release), without requiring
|
||||
them to rebuild the gloox library themselves. And we don't want to provide ~8
|
||||
different prebuilt versions of the library.
|
||||
|
||||
glooxwrapper replaces the gloox API with a version that is safe to use across
|
||||
compiler versions. glooxwrapper and gloox must be compiled together with the
|
||||
same version, but the resulting library can be used with any other compiler.
|
||||
|
||||
This is the small subset of the API that the game currently uses, with no
|
||||
attempt to be comprehensive.
|
||||
|
||||
General design and rules:
|
||||
|
||||
* There is a strict boundary between gloox+glooxwrapper.cpp, and the game
|
||||
code that includes glooxwrapper.h.
|
||||
Objects allocated with new/delete on one side of the boundary must be
|
||||
freed/allocated on the same side.
|
||||
Objects allocated with glooxwrapper_alloc()/glooxwrapper_delete() can be
|
||||
freely shared across the boundary.
|
||||
|
||||
* glooxwrapper.h and users of glooxwrapper must not use any types from
|
||||
the gloox namespace, except for enums.
|
||||
|
||||
* std::string is replaced with glooxwrapper::string,
|
||||
std::list with glooxwrapper::list
|
||||
|
||||
* Most glooxwrapper classes are simple wrappers around gloox classes.
|
||||
Some always take ownership of their wrapped gloox object (i.e. their
|
||||
destructor will delete the wrapped object too); some never do; and some
|
||||
can be used either way (indicated by an m_Owned field).
|
||||
|
||||
*/
|
||||
|
||||
#if OS_WIN
|
||||
# include "lib/sysdep/os/win/win.h"
|
||||
// Prevent gloox pulling in windows.h
|
||||
# define _WINDOWS_
|
||||
#endif
|
||||
|
||||
#include <gloox/client.h>
|
||||
#include <gloox/mucroom.h>
|
||||
#include <gloox/registration.h>
|
||||
#include <gloox/message.h>
|
||||
#include <gloox/jinglecontent.h>
|
||||
#include <gloox/jingleiceudp.h>
|
||||
#include <gloox/jinglesessionhandler.h>
|
||||
#include <gloox/jinglesessionmanager.h>
|
||||
|
||||
#include <cstring>
|
||||
|
||||
// Gloox leaves some #define up, we need to undefine them.
|
||||
#undef lookup
|
||||
#undef lookup2
|
||||
#undef deflookup
|
||||
#undef deflookup2
|
||||
|
||||
#if OS_WIN
|
||||
#define GLOOXWRAPPER_API __declspec(dllexport)
|
||||
#else
|
||||
#define GLOOXWRAPPER_API
|
||||
#endif
|
||||
|
||||
namespace glooxwrapper
|
||||
{
|
||||
class Client;
|
||||
class DataForm;
|
||||
class DelayedDelivery;
|
||||
class Disco;
|
||||
class IQ;
|
||||
class JID;
|
||||
class MUCRoom;
|
||||
class MUCRoomConfigHandler;
|
||||
class Message;
|
||||
class MessageSession;
|
||||
class OOB;
|
||||
class Presence;
|
||||
class StanzaError;
|
||||
class StanzaExtension;
|
||||
class Tag;
|
||||
|
||||
class ClientImpl;
|
||||
class MUCRoomHandlerWrapper;
|
||||
class SessionHandlerWrapper;
|
||||
|
||||
GLOOXWRAPPER_API void* glooxwrapper_alloc(size_t size);
|
||||
GLOOXWRAPPER_API void glooxwrapper_free(void* p);
|
||||
|
||||
class string
|
||||
{
|
||||
private:
|
||||
size_t m_Size;
|
||||
char* m_Data;
|
||||
public:
|
||||
string()
|
||||
{
|
||||
m_Size = 0;
|
||||
m_Data = (char*)glooxwrapper_alloc(1);
|
||||
m_Data[0] = '\0';
|
||||
}
|
||||
|
||||
string(const string& str)
|
||||
{
|
||||
m_Size = str.m_Size;
|
||||
m_Data = (char*)glooxwrapper_alloc(m_Size + 1);
|
||||
memcpy(m_Data, str.m_Data, m_Size + 1);
|
||||
}
|
||||
|
||||
string(const std::string& str) : m_Data(NULL)
|
||||
{
|
||||
m_Size = str.size();
|
||||
m_Data = (char*)glooxwrapper_alloc(m_Size + 1);
|
||||
memcpy(m_Data, str.c_str(), m_Size + 1);
|
||||
}
|
||||
|
||||
string(const char* str)
|
||||
{
|
||||
m_Size = strlen(str);
|
||||
m_Data = (char*)glooxwrapper_alloc(m_Size + 1);
|
||||
memcpy(m_Data, str, m_Size + 1);
|
||||
}
|
||||
|
||||
string& operator=(const string& str)
|
||||
{
|
||||
if (this != &str)
|
||||
{
|
||||
glooxwrapper_free(m_Data);
|
||||
m_Size = str.m_Size;
|
||||
m_Data = (char*)glooxwrapper_alloc(m_Size + 1);
|
||||
memcpy(m_Data, str.m_Data, m_Size + 1);
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
~string()
|
||||
{
|
||||
glooxwrapper_free(m_Data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gloox strings are UTF encoded, so don't forget to decode it before passing it to the GUI!
|
||||
*/
|
||||
std::string to_string() const
|
||||
{
|
||||
return std::string(m_Data, m_Size);
|
||||
}
|
||||
|
||||
const char* c_str() const
|
||||
{
|
||||
return m_Data;
|
||||
}
|
||||
|
||||
bool empty() const
|
||||
{
|
||||
return m_Size == 0;
|
||||
}
|
||||
|
||||
bool operator==(const char* str) const
|
||||
{
|
||||
return strcmp(m_Data, str) == 0;
|
||||
}
|
||||
|
||||
bool operator!=(const char* str) const
|
||||
{
|
||||
return strcmp(m_Data, str) != 0;
|
||||
}
|
||||
|
||||
bool operator==(const string& str) const
|
||||
{
|
||||
return strcmp(m_Data, str.m_Data) == 0;
|
||||
}
|
||||
|
||||
bool operator<(const string& str) const
|
||||
{
|
||||
return strcmp(m_Data, str.m_Data) < 0;
|
||||
}
|
||||
};
|
||||
|
||||
static inline std::ostream& operator<<(std::ostream& stream, const string& string)
|
||||
{
|
||||
return stream << string.c_str();
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
class list
|
||||
{
|
||||
private:
|
||||
struct node
|
||||
{
|
||||
node(const T& item) : m_Item(item), m_Next(NULL) {}
|
||||
T m_Item;
|
||||
node* m_Next;
|
||||
};
|
||||
node* m_Head;
|
||||
node* m_Tail;
|
||||
|
||||
public:
|
||||
struct const_iterator
|
||||
{
|
||||
const node* m_Node;
|
||||
const_iterator(const node* n) : m_Node(n) {}
|
||||
bool operator!=(const const_iterator& it) { return m_Node != it.m_Node; }
|
||||
const_iterator& operator++() { m_Node = m_Node->m_Next; return *this; }
|
||||
const T& operator*() { return m_Node->m_Item; }
|
||||
};
|
||||
const_iterator begin() const { return const_iterator(m_Head); }
|
||||
const_iterator end() const { return const_iterator(NULL); }
|
||||
|
||||
list() : m_Head(NULL), m_Tail(NULL) {}
|
||||
|
||||
list(const list& src) : m_Head(NULL), m_Tail(NULL)
|
||||
{
|
||||
*this = src;
|
||||
}
|
||||
|
||||
list& operator=(const list& src)
|
||||
{
|
||||
if (this != &src)
|
||||
{
|
||||
clear();
|
||||
for (node* n = src.m_Head; n; n = n->m_Next)
|
||||
push_back(n->m_Item);
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
~list()
|
||||
{
|
||||
clear();
|
||||
}
|
||||
|
||||
void push_back(const T& item)
|
||||
{
|
||||
node* n = new (glooxwrapper_alloc(sizeof(node))) node(item);
|
||||
if (m_Tail)
|
||||
m_Tail->m_Next = n;
|
||||
m_Tail = n;
|
||||
if (!m_Head)
|
||||
m_Head = n;
|
||||
}
|
||||
|
||||
void clear()
|
||||
{
|
||||
node* n = m_Head;
|
||||
while (n)
|
||||
{
|
||||
node* next = n->m_Next;
|
||||
glooxwrapper_free(n);
|
||||
n = next;
|
||||
}
|
||||
m_Head = m_Tail = NULL;
|
||||
}
|
||||
|
||||
const T& front() const
|
||||
{
|
||||
return *begin();
|
||||
}
|
||||
};
|
||||
|
||||
typedef glooxwrapper::list<Tag*> TagList;
|
||||
typedef glooxwrapper::list<const Tag*> ConstTagList;
|
||||
|
||||
struct CertInfo
|
||||
{
|
||||
int status;
|
||||
bool chain;
|
||||
string issuer;
|
||||
string server;
|
||||
int date_from;
|
||||
int date_to;
|
||||
string protocol;
|
||||
string cipher;
|
||||
string mac;
|
||||
string compression;
|
||||
};
|
||||
|
||||
struct RegistrationFields
|
||||
{
|
||||
string username;
|
||||
string nick;
|
||||
string password;
|
||||
string name;
|
||||
string first;
|
||||
string last;
|
||||
string email;
|
||||
string address;
|
||||
string city;
|
||||
string state;
|
||||
string zip;
|
||||
string phone;
|
||||
string url;
|
||||
string date;
|
||||
#if !OS_WIN
|
||||
string misc;
|
||||
string text;
|
||||
#endif
|
||||
};
|
||||
|
||||
struct MUCRoomParticipant
|
||||
{
|
||||
JID* nick;
|
||||
gloox::MUCRoomAffiliation affiliation;
|
||||
gloox::MUCRoomRole role;
|
||||
JID* jid;
|
||||
int flags;
|
||||
string reason;
|
||||
JID* actor;
|
||||
string newNick;
|
||||
string status;
|
||||
JID* alternate;
|
||||
};
|
||||
|
||||
|
||||
class GLOOXWRAPPER_API ConnectionListener
|
||||
{
|
||||
public:
|
||||
virtual ~ConnectionListener() {}
|
||||
virtual void onConnect() = 0;
|
||||
virtual void onDisconnect(gloox::ConnectionError e) = 0;
|
||||
virtual bool onTLSConnect(const CertInfo& info) = 0;
|
||||
};
|
||||
|
||||
class GLOOXWRAPPER_API IqHandler
|
||||
{
|
||||
public:
|
||||
virtual ~IqHandler() {}
|
||||
virtual bool handleIq(const IQ& iq) = 0;
|
||||
virtual void handleIqID(const IQ& iq, int context) = 0;
|
||||
};
|
||||
|
||||
class GLOOXWRAPPER_API MessageHandler
|
||||
{
|
||||
public:
|
||||
virtual ~MessageHandler() {}
|
||||
virtual void handleMessage(const Message& msg, MessageSession* session = 0) = 0; // MessageSession not supported
|
||||
};
|
||||
|
||||
class GLOOXWRAPPER_API MUCRoomHandler
|
||||
{
|
||||
public:
|
||||
virtual ~MUCRoomHandler() {}
|
||||
virtual void handleMUCParticipantPresence(MUCRoom& room, const MUCRoomParticipant participant, const Presence& presence) = 0;
|
||||
virtual void handleMUCMessage(MUCRoom& room, const Message& msg, bool priv) = 0;
|
||||
virtual void handleMUCError(MUCRoom& room, gloox::StanzaError error) = 0;
|
||||
virtual void handleMUCSubject(MUCRoom& room, const string& nick, const string& subject) = 0;
|
||||
};
|
||||
|
||||
class GLOOXWRAPPER_API RegistrationHandler
|
||||
{
|
||||
public:
|
||||
virtual ~RegistrationHandler() {}
|
||||
virtual void handleRegistrationFields(const JID& from, int fields, string instructions) = 0;
|
||||
virtual void handleAlreadyRegistered(const JID& from) = 0;
|
||||
virtual void handleRegistrationResult(const JID& from, gloox::RegistrationResult regResult) = 0;
|
||||
virtual void handleDataForm(const JID& from, const DataForm& form) = 0; // DataForm not supported
|
||||
virtual void handleOOB(const JID& from, const OOB& oob) = 0; // OOB not supported
|
||||
};
|
||||
|
||||
class GLOOXWRAPPER_API StanzaExtension
|
||||
{
|
||||
public:
|
||||
StanzaExtension(int type) : m_extensionType(type) {}
|
||||
virtual ~StanzaExtension() {}
|
||||
virtual const string& filterString() const = 0;
|
||||
virtual StanzaExtension* newInstance(const Tag* tag) const = 0;
|
||||
virtual glooxwrapper::Tag* tag() const = 0;
|
||||
virtual StanzaExtension* clone() const = 0;
|
||||
|
||||
int extensionType() const { return m_extensionType; }
|
||||
private:
|
||||
int m_extensionType;
|
||||
};
|
||||
|
||||
|
||||
class GLOOXWRAPPER_API Client
|
||||
{
|
||||
NONCOPYABLE(Client);
|
||||
private:
|
||||
gloox::Client* m_Wrapped;
|
||||
ClientImpl* m_Impl;
|
||||
Disco* m_DiscoWrapper;
|
||||
|
||||
public:
|
||||
gloox::Client* getWrapped() { return m_Wrapped; }
|
||||
|
||||
bool connect(bool block = true);
|
||||
gloox::ConnectionError recv(int timeout = -1);
|
||||
const string getID() const;
|
||||
const string getJID() const;
|
||||
void send(const IQ& iq);
|
||||
|
||||
void setTls(gloox::TLSPolicy tls);
|
||||
void setCompression(bool compression);
|
||||
|
||||
void setSASLMechanisms(int mechanisms);
|
||||
void registerStanzaExtension(StanzaExtension* ext);
|
||||
void registerConnectionListener(ConnectionListener* cl);
|
||||
void registerIqHandler(IqHandler* ih, int exttype);
|
||||
void registerMessageHandler(MessageHandler* mh);
|
||||
|
||||
bool removePresenceExtension(int type);
|
||||
|
||||
Disco* disco() const { return m_DiscoWrapper; }
|
||||
|
||||
Client(const string& server);
|
||||
Client(const JID& jid, const string& password, int port = -1);
|
||||
~Client();
|
||||
|
||||
void setPresence(gloox::Presence::PresenceType pres, int priority, const string& status = "");
|
||||
void disconnect();
|
||||
};
|
||||
|
||||
class GLOOXWRAPPER_API DelayedDelivery
|
||||
{
|
||||
NONCOPYABLE(DelayedDelivery);
|
||||
private:
|
||||
const gloox::DelayedDelivery* m_Wrapped;
|
||||
public:
|
||||
DelayedDelivery(const gloox::DelayedDelivery* wrapped);
|
||||
const string stamp() const;
|
||||
};
|
||||
|
||||
class GLOOXWRAPPER_API Disco
|
||||
{
|
||||
NONCOPYABLE(Disco);
|
||||
private:
|
||||
gloox::Disco* m_Wrapped;
|
||||
public:
|
||||
Disco(gloox::Disco* wrapped);
|
||||
void setVersion(const string& name, const string& version, const string& os = "");
|
||||
void setIdentity(const string& category, const string& type, const string& name = "");
|
||||
};
|
||||
|
||||
class GLOOXWRAPPER_API IQ
|
||||
{
|
||||
NONCOPYABLE(IQ);
|
||||
private:
|
||||
gloox::IQ* m_Wrapped;
|
||||
bool m_Owned;
|
||||
public:
|
||||
const gloox::IQ& getWrapped() const { return *m_Wrapped; }
|
||||
IQ(const gloox::IQ& iq) : m_Wrapped(const_cast<gloox::IQ*>(&iq)), m_Owned(false) { }
|
||||
|
||||
IQ(gloox::IQ::IqType type, const JID& to, const string& id);
|
||||
~IQ();
|
||||
|
||||
void addExtension(const StanzaExtension* se);
|
||||
const StanzaExtension* findExtension(int type) const;
|
||||
|
||||
template<class T>
|
||||
inline const T* findExtension(int type) const
|
||||
{
|
||||
return static_cast<const T*>(findExtension(type));
|
||||
}
|
||||
|
||||
gloox::IQ::IqType subtype() const;
|
||||
const string id() const;
|
||||
const gloox::JID& from() const;
|
||||
|
||||
gloox::StanzaError error_error() const; // wrapper for ->error()->error()
|
||||
Tag* tag() const;
|
||||
};
|
||||
|
||||
class GLOOXWRAPPER_API JID
|
||||
{
|
||||
NONCOPYABLE(JID);
|
||||
private:
|
||||
gloox::JID* m_Wrapped;
|
||||
bool m_Owned;
|
||||
void init(const char* data, size_t len);
|
||||
public:
|
||||
const gloox::JID& getWrapped() const { return *m_Wrapped; }
|
||||
JID(const gloox::JID& jid) : m_Wrapped(const_cast<gloox::JID*>(&jid)), m_Owned(false) { }
|
||||
|
||||
JID();
|
||||
JID(const string& jid);
|
||||
JID(const std::string& jid) { init(jid.c_str(), jid.size()); }
|
||||
~JID();
|
||||
|
||||
string username() const;
|
||||
string resource() const;
|
||||
};
|
||||
|
||||
class GLOOXWRAPPER_API Message
|
||||
{
|
||||
NONCOPYABLE(Message);
|
||||
private:
|
||||
gloox::Message* m_Wrapped;
|
||||
bool m_Owned;
|
||||
glooxwrapper::JID m_From;
|
||||
glooxwrapper::DelayedDelivery* m_DelayedDelivery;
|
||||
public:
|
||||
Message(gloox::Message* wrapped, bool owned);
|
||||
~Message();
|
||||
gloox::Message::MessageType subtype() const;
|
||||
const JID& from() const;
|
||||
string body() const;
|
||||
string subject(const string& lang = "default") const;
|
||||
string thread() const;
|
||||
const glooxwrapper::DelayedDelivery* when() const;
|
||||
};
|
||||
|
||||
class GLOOXWRAPPER_API MUCRoom
|
||||
{
|
||||
NONCOPYABLE(MUCRoom);
|
||||
private:
|
||||
gloox::MUCRoom* m_Wrapped;
|
||||
MUCRoomHandlerWrapper* m_HandlerWrapper;
|
||||
bool m_Owned;
|
||||
public:
|
||||
MUCRoom(gloox::MUCRoom* room, bool owned);
|
||||
MUCRoom(Client* parent, const JID& nick, MUCRoomHandler* mrh, MUCRoomConfigHandler* mrch = 0);
|
||||
~MUCRoom();
|
||||
const string nick() const;
|
||||
const string name() const;
|
||||
const string service() const;
|
||||
void join(gloox::Presence::PresenceType type = gloox::Presence::Available, const string& status = "", int priority = 0);
|
||||
void leave(const string& msg = "");
|
||||
void send(const string& message);
|
||||
void setNick(const string& nick);
|
||||
void setPresence(gloox::Presence::PresenceType presence, const string& msg = "");
|
||||
void setRequestHistory(int value, gloox::MUCRoom::HistoryRequestType type);
|
||||
void kick(const string& nick, const string& reason);
|
||||
void ban(const string& nick, const string& reason);
|
||||
};
|
||||
|
||||
class GLOOXWRAPPER_API Presence
|
||||
{
|
||||
gloox::Presence::PresenceType m_Presence;
|
||||
public:
|
||||
Presence(gloox::Presence::PresenceType presence) : m_Presence(presence) {}
|
||||
gloox::Presence::PresenceType presence() const { return m_Presence; }
|
||||
};
|
||||
|
||||
class GLOOXWRAPPER_API Registration
|
||||
{
|
||||
NONCOPYABLE(Registration);
|
||||
private:
|
||||
gloox::Registration* m_Wrapped;
|
||||
std::list<std::shared_ptr<gloox::RegistrationHandler> > m_RegistrationHandlers;
|
||||
public:
|
||||
Registration(Client* parent);
|
||||
~Registration();
|
||||
void fetchRegistrationFields();
|
||||
bool createAccount(int fields, const RegistrationFields& values);
|
||||
void registerRegistrationHandler(RegistrationHandler* rh);
|
||||
};
|
||||
|
||||
class GLOOXWRAPPER_API Tag
|
||||
{
|
||||
NONCOPYABLE(Tag);
|
||||
private:
|
||||
gloox::Tag* m_Wrapped;
|
||||
bool m_Owned;
|
||||
|
||||
Tag(const string& name);
|
||||
Tag(const string& name, const string& cdata);
|
||||
Tag(gloox::Tag* wrapped, bool owned) : m_Wrapped(wrapped), m_Owned(owned) {}
|
||||
~Tag();
|
||||
|
||||
public:
|
||||
// Internal use:
|
||||
gloox::Tag* getWrapped() { return m_Wrapped; }
|
||||
gloox::Tag* stealWrapped() { m_Owned = false; return m_Wrapped; }
|
||||
static Tag* allocate(gloox::Tag* wrapped, bool owned);
|
||||
|
||||
// Instead of using new/delete, Tags must be allocated/freed with these functions
|
||||
static Tag* allocate(const string& name);
|
||||
static Tag* allocate(const string& name, const string& cdata);
|
||||
static void free(const Tag* tag);
|
||||
|
||||
bool addAttribute(const string& name, const string& value);
|
||||
string findAttribute(const string& name) const;
|
||||
Tag* clone() const;
|
||||
string xmlns() const;
|
||||
bool setXmlns(const string& xmlns);
|
||||
string xml() const;
|
||||
void addChild(Tag* child);
|
||||
string name() const;
|
||||
string cdata() const;
|
||||
const Tag* findTag_clone(const string& expression) const; // like findTag but must be Tag::free()d
|
||||
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
|
||||
{
|
||||
|
||||
class GLOOXWRAPPER_API Plugin
|
||||
{
|
||||
protected:
|
||||
const gloox::Jingle::Plugin* m_Wrapped;
|
||||
bool m_Owned;
|
||||
|
||||
public:
|
||||
Plugin(const gloox::Jingle::Plugin* wrapped, bool owned) : m_Wrapped(wrapped), m_Owned(owned) {}
|
||||
|
||||
virtual ~Plugin();
|
||||
|
||||
const Plugin findPlugin(int type) const;
|
||||
const gloox::Jingle::Plugin* getWrapped() const { return m_Wrapped; }
|
||||
};
|
||||
|
||||
typedef list<const Plugin*> PluginList;
|
||||
|
||||
/**
|
||||
* See XEP-0176: Jingle ICE-UDP Transport Method
|
||||
*/
|
||||
class GLOOXWRAPPER_API ICEUDP
|
||||
{
|
||||
public:
|
||||
struct Candidate {
|
||||
string ip;
|
||||
int port;
|
||||
};
|
||||
private:
|
||||
// Class not implemented as it is not used.
|
||||
ICEUDP() = delete;
|
||||
};
|
||||
|
||||
class GLOOXWRAPPER_API Session
|
||||
{
|
||||
protected:
|
||||
gloox::Jingle::Session* m_Wrapped;
|
||||
bool m_Owned;
|
||||
|
||||
public:
|
||||
class GLOOXWRAPPER_API Jingle
|
||||
{
|
||||
private:
|
||||
const gloox::Jingle::Session::Jingle* m_Wrapped;
|
||||
bool m_Owned;
|
||||
public:
|
||||
Jingle(const gloox::Jingle::Session::Jingle* wrapped, bool owned) : m_Wrapped(wrapped), m_Owned(owned) {}
|
||||
~Jingle()
|
||||
{
|
||||
if (m_Owned)
|
||||
delete m_Wrapped;
|
||||
}
|
||||
ICEUDP::Candidate getCandidate() const;
|
||||
};
|
||||
|
||||
Session(gloox::Jingle::Session* wrapped, bool owned);
|
||||
~Session();
|
||||
|
||||
bool sessionInitiate(const char* ipStr, uint16_t port);
|
||||
};
|
||||
|
||||
class GLOOXWRAPPER_API SessionHandler
|
||||
{
|
||||
public:
|
||||
virtual ~SessionHandler() {}
|
||||
virtual void handleSessionAction(gloox::Jingle::Action action, Session& session, const Session::Jingle& jingle) = 0;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
class GLOOXWRAPPER_API SessionManager
|
||||
{
|
||||
private:
|
||||
gloox::Jingle::SessionManager* m_Wrapped;
|
||||
SessionHandlerWrapper* m_HandlerWrapper;
|
||||
|
||||
public:
|
||||
SessionManager(Client* parent, Jingle::SessionHandler* sh);
|
||||
~SessionManager();
|
||||
void registerPlugins();
|
||||
Jingle::Session createSession(const JID& callee);
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif // INCLUDED_GLOOXWRAPPER_H
|
||||
|
|
@ -23,11 +23,6 @@
|
|||
#include "lobby/XmppClient.h"
|
||||
#include "scriptinterface/ScriptConversions.h"
|
||||
|
||||
template<> void Script::ToJSVal<glooxwrapper::string>(const ScriptRequest& rq, JS::MutableHandleValue ret, const glooxwrapper::string& val)
|
||||
{
|
||||
ToJSVal(rq, ret, wstring_from_utf8(val.to_string()));
|
||||
}
|
||||
|
||||
template<> void Script::ToJSVal<gloox::Presence::PresenceType>(const ScriptRequest& rq, JS::MutableHandleValue ret, const gloox::Presence::PresenceType& val)
|
||||
{
|
||||
ToJSVal(rq, ret, XmppClient::GetPresenceString(val));
|
||||
|
|
|
|||
|
|
@ -1,18 +0,0 @@
|
|||
/* Copyright (C) 2009 Wildfire Games.
|
||||
* This file is part of 0 A.D.
|
||||
*
|
||||
* 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
|
||||
* the Free Software Foundation, either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* 0 A.D. is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with 0 A.D. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "precompiled.h"
|
||||
|
|
@ -1,18 +0,0 @@
|
|||
/* Copyright (C) 2009 Wildfire Games.
|
||||
* This file is part of 0 A.D.
|
||||
*
|
||||
* 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
|
||||
* the Free Software Foundation, either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* 0 A.D. is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with 0 A.D. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "lib/precompiled.h" // common precompiled header
|
||||
Loading…
Reference in a new issue