Skip to content

Commit b0c2d42

Browse files
Robert ColeErich Keane
Robert Cole
authored and
Erich Keane
committed
Implementation and tests for XMPP service discovery and XMPP ping.
These are basic implementations of the representative iq messages for each type of service and do not include any additional parsing or timer handling (for ping). Change-Id: I9d3eece8092a3ced347ab0ed04efa171109a9ba3 Signed-off-by: Robert Cole <[email protected]> Reviewed-on: https://gerrit.iotivity.org/gerrit/1184 Reviewed-by: Charlie Lenahan <[email protected]> Reviewed-by: Erich Keane <[email protected]> Tested-by: Erich Keane <[email protected]>
1 parent 0786c72 commit b0c2d42

14 files changed

+651
-37
lines changed

WinDT/CCFXmpp_Tests/CCFXmpp_Tests.vcxproj

+2
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,7 @@ xcopy /y /d "$(SolutionDir)\packages\libssh2.redist.1.4.3.1\build\native\bin\v11
277277
</ItemDefinitionGroup>
278278
<ItemGroup>
279279
<ClInclude Include="..\..\test\xmpp_connect_config.h" />
280+
<ClInclude Include="..\..\test\xmpp_connect_establish.h" />
280281
<ClInclude Include="..\..\test\xmpp_dummy_server.h" />
281282
<ClInclude Include="..\..\test\xmpp_test_config.h" />
282283
<ClInclude Include="stdafx.h" />
@@ -302,6 +303,7 @@ xcopy /y /d "$(SolutionDir)\packages\libssh2.redist.1.4.3.1\build\native\bin\v11
302303
<ClCompile Include="..\..\test\unittest_base.cpp" />
303304
<ClCompile Include="..\..\test\xmpp_compliance_tests.cpp" />
304305
<ClCompile Include="..\..\test\xmpp_connect_config.cpp" />
306+
<ClCompile Include="..\..\test\xmpp_connect_establish.cpp" />
305307
<ClCompile Include="..\..\test\xmpp_dummy_server.cpp" />
306308
<ClCompile Include="..\..\test\xmpp_tests.cpp" />
307309
<ClCompile Include="stdafx.cpp">

WinDT/CCFXmpp_Tests/CCFXmpp_Tests.vcxproj.filters

+6
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@
3030
<ClInclude Include="..\..\test\xmpp_connect_config.h">
3131
<Filter>Header Files</Filter>
3232
</ClInclude>
33+
<ClInclude Include="..\..\test\xmpp_connect_establish.h">
34+
<Filter>Header Files</Filter>
35+
</ClInclude>
3336
</ItemGroup>
3437
<ItemGroup>
3538
<ClCompile Include="stdafx.cpp">
@@ -77,6 +80,9 @@
7780
<ClCompile Include="..\..\test\xmpp_connect_config.cpp">
7881
<Filter>Source Files</Filter>
7982
</ClCompile>
83+
<ClCompile Include="..\..\test\xmpp_connect_establish.cpp">
84+
<Filter>Source Files</Filter>
85+
</ClCompile>
8086
</ItemGroup>
8187
<ItemGroup>
8288
<None Include="packages.config" />

src/xmpp/xmppclient.cpp

+34-29
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,44 @@
3939
#include "../xmpp/xmppconfig.h"
4040
#include "../xmpp/jabberid.h"
4141

42+
4243
// TOOD: Move interface when refactoring for BOSH 'streams'
4344
#include "../connect/tcpclient.h"
4445

4546
#include <iostream>
4647

4748

4849

50+
51+
/// @mainpage Iotivity XMPP Client
52+
///
53+
/// @section intro Introduction
54+
///
55+
/// The Iotivity XMPP Client is a basic C++ XMPP client implementation written to provide
56+
/// cross-platform support for XMPP for Iotivity and the CCF project.
57+
///
58+
/// @section XMPP Support
59+
///
60+
/// <ul>
61+
/// <li>RFC 6120 (XMPP Core)</li>
62+
/// <li>SASL
63+
/// <ul>
64+
/// <li>RFC 4616 (PLAIN)</li>
65+
/// </ul>
66+
/// </li>
67+
/// <li>XMPP Extensions
68+
/// <ul>
69+
/// <li>XEP-0077 (In-Band Registration)</li>
70+
/// <li>XEP-0030 (Service-Discovery) [Basic queries only]</li>
71+
/// <li>XEP-0199 (XMPP Ping) [Timer-based ping/pong still a WIP]</li>
72+
/// </ul>
73+
/// </li>
74+
/// </ul>
75+
76+
77+
4978
/// @addtogroup XMPP
79+
/// @{
5080
/// Create and start an XMPP client:
5181
/// @code
5282
///
@@ -101,30 +131,7 @@
101131
/// {}
102132
///
103133
/// @endcode
104-
105-
106-
/// @mainpage Iotivity XMPP Client
107-
///
108-
/// @section intro Introduction
109-
///
110-
/// The Iotivity XMPP Client is a basic C++ XMPP client implementation written to provide
111-
/// cross-platform support for XMPP for Iotivity and the CCF project.
112-
///
113-
/// @section XMPP Support
114-
///
115-
/// <ul>
116-
/// <li>RFC 6120 (XMPP Core)</li>
117-
/// <li>SASL
118-
/// <ul>
119-
/// <li>RFC 4616 (PLAIN)</li>
120-
/// </ul>
121-
/// </li>
122-
/// <li>XMPP Extensions
123-
/// <ul>
124-
/// <li>XEP-0077 (In-Band Registration)</li>
125-
/// </ul>
126-
/// </li>
127-
/// </ul>
134+
/// @}
128135

129136

130137

@@ -234,7 +241,7 @@ namespace Iotivity
234241
}
235242
}
236243

237-
// const static size_t DEFAULT_BUFFER_SIZE = 4096;
244+
// const static size_t DEFAULT_BUFFER_SIZE = 4096;
238245

239246
void XmppConnection::receive(XMLElement::Ptr &payload)
240247
{
@@ -987,6 +994,7 @@ namespace Iotivity
987994
onConnected().fire(XmppConnectedEvent(
988995
connect_error::SUCCESS));
989996
m_boundPromise.set_value(m_boundJabberId);
997+
m_negotiatedPromise.set_value();
990998
}
991999
else
9921000
{
@@ -1486,7 +1494,7 @@ namespace Iotivity
14861494
// Action runner for the XMPP client.
14871495
struct XmppClientRunner: public ActionRunner<std::shared_ptr<IXmppConnection>, XmppContext>
14881496
{
1489-
XmppClientRunner(XmppClient &owner) /*: m_owner(owner)*/ {}
1497+
XmppClientRunner(XmppClient &) {}
14901498

14911499
protected:
14921500
virtual std::thread createActionThread(std::shared_ptr<runner_queue> queue,
@@ -1527,9 +1535,6 @@ namespace Iotivity
15271535
}
15281536
});
15291537
}
1530-
1531-
private:
1532-
// XmppClient &m_owner;
15331538
};
15341539
/// @endcond
15351540

src/xmpp/xmppclient.h

+4-6
Original file line numberDiff line numberDiff line change
@@ -139,12 +139,10 @@ namespace Iotivity
139139

140140
virtual SyncEvent<XmppStreamCreatedEvent> &onStreamCreated();
141141

142-
typedef std::shared_ptr<std::promise<std::shared_ptr<IXmppStream>>>
143-
XmppStreamPromise;
144-
145-
void initiateXMPP(const XmppConfig &config,
146-
std::shared_ptr<IXmppConnection> remoteServer,
147-
XmppStreamPromise xmppConnection = XmppStreamPromise());
142+
virtual void initiateXMPP(const XmppConfig &config,
143+
std::shared_ptr<IXmppConnection> remoteServer,
144+
XmppStreamPromise xmppConnection =
145+
XmppStreamPromise()) override;
148146

149147
protected:
150148
XmppClient();

src/xmpp/xmppconfig.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ namespace Iotivity
4343
{
4444
void operator()(XmppConfigImpl *);
4545
};
46-
/// @endcode
46+
/// @endcond
4747

4848
}
4949
}

src/xmpp/xmppinterfaces.h

+8
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ namespace Iotivity
5353
{
5454
struct SaslResult;
5555
class connect_error;
56+
class XmppConfig;
5657

5758

5859
/// @brief XML Stream interface. Provides a stream from which XML payloads may be
@@ -226,8 +227,15 @@ namespace Iotivity
226227
class XMPP_API IXmppClient
227228
{
228229
public:
230+
typedef std::shared_ptr<std::promise<std::shared_ptr<IXmppStream>>>
231+
XmppStreamPromise;
232+
229233
virtual ~IXmppClient() {}
230234

235+
virtual void initiateXMPP(const XmppConfig &config,
236+
std::shared_ptr<IXmppConnection> remoteServer,
237+
XmppStreamPromise xmppConnection =
238+
XmppStreamPromise()) = 0;
231239
virtual SyncEvent<XmppStreamCreatedEvent> &onStreamCreated() = 0;
232240
};
233241

src/xmpp/xmppping.cpp

+58-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
#include "stdafx.h"
2727

2828
#include "xmppping.h"
29-
29+
#include "jabberid.h"
3030
#include "../connect/connecterror.h"
3131

3232
#ifndef DISABLE_SUPPORT_XEP0199
@@ -38,6 +38,63 @@ namespace Iotivity
3838
{
3939
namespace Xmpp
4040
{
41+
static const string XMPP_PING_NS = "urn:xmpp:ping";
42+
43+
shared_ptr<XmppPing::Params> XmppPing::Params::create()
44+
{
45+
return shared_ptr<Params>(new Params);
46+
}
47+
48+
bool XmppPing::Params::supportsExtension(const string &extensionName) const
49+
{
50+
return extensionName == XmppPing::extensionName();
51+
}
52+
53+
XmppPing::XmppPing(shared_ptr<IXmppStream> overStream):
54+
XmppExtension(overStream)
55+
{}
56+
57+
XmppPing::~XmppPing()
58+
{
59+
// Called here so any captured this is not stale when the queries halt.
60+
haltSafeQueries();
61+
}
62+
63+
void XmppPing::assignConfiguration(std::shared_ptr<IExtensionParams> config)
64+
{
65+
if (config && config->supportsExtension(XmppPing::extensionName()))
66+
{
67+
m_config = static_pointer_cast<Params>(config);
68+
}
69+
}
70+
71+
void XmppPing::sendPing(const JabberID &target, PongCallback onPong)
72+
{
73+
XMLElement::Ptr request = constructIQ("get", target.full());
74+
XMLElement::Ptr query = request->owner()->createElement("ping");
75+
query->setAttribute("xmlns", XMPP_PING_NS);
76+
request->appendChild(query);
77+
78+
sendSafeQuery(move(request),
79+
[this, onPong]
80+
(const connect_error & ce, XMLElement::Ptr response)
81+
{
82+
if (!ce.succeeded())
83+
{
84+
onPong(ce);
85+
return;
86+
}
87+
88+
connect_error result = testAndProcessErrorResponse(response);
89+
if (result.succeeded())
90+
{
91+
92+
}
93+
onPong(result);
94+
});
95+
}
96+
97+
4198
}
4299
}
43100

src/xmpp/xmppping.h

+36
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,42 @@ namespace Iotivity
3939
{
4040
namespace Xmpp
4141
{
42+
class connect_error;
43+
44+
// XEP-0199 XMPP Ping
45+
class XmppPing: public XmppExtension
46+
{
47+
public:
48+
class XMPP_API Params: public IExtensionParams
49+
{
50+
public:
51+
Params() = default;
52+
Params(const Params &) = default;
53+
static std::shared_ptr<Params> create();
54+
55+
virtual bool supportsExtension(const std::string &extensionName) const override;
56+
57+
private:
58+
59+
};
60+
public:
61+
XmppPing(std::shared_ptr<IXmppStream> overStream);
62+
virtual ~XmppPing() override;
63+
64+
static std::string extensionName() { return "XEP0199"; }
65+
virtual std::string getExtensionName() const override
66+
{
67+
return XmppPing::extensionName();
68+
}
69+
70+
virtual void assignConfiguration(std::shared_ptr<IExtensionParams> config) override;
71+
72+
typedef std::function<void(const connect_error &)> PongCallback;
73+
void sendPing(const JabberID &target, PongCallback onPong = PongCallback());
74+
75+
private:
76+
std::shared_ptr<Params> m_config;
77+
};
4278
}
4379
}
4480

0 commit comments

Comments
 (0)