forked from mirrors/0ad
Move ComputeTimestamp to XmppClient.cpp
It is only used there.
This commit is contained in:
+29
-26
@@ -50,23 +50,50 @@
|
|||||||
#include <unicode/utypes.h>
|
#include <unicode/utypes.h>
|
||||||
#include <utility>
|
#include <utility>
|
||||||
|
|
||||||
|
namespace
|
||||||
|
{
|
||||||
//debug
|
//debug
|
||||||
#if 1
|
#if 1
|
||||||
#define DbgXMPP(x)
|
#define DbgXMPP(x)
|
||||||
#else
|
#else
|
||||||
#define DbgXMPP(x) std::cout << "XMPP DEBUG: " << x << std::endl;
|
#define DbgXMPP(x) std::cout << "XMPP DEBUG: " << x << std::endl;
|
||||||
|
|
||||||
static std::string tag_xml(const gloox::IQ& iq)
|
std::string tag_xml(const gloox::IQ& iq)
|
||||||
{
|
{
|
||||||
return iq.tag()->xml();
|
return iq.tag()->xml();
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static std::string tag_name(const gloox::IQ& iq)
|
std::string tag_name(const gloox::IQ& iq)
|
||||||
{
|
{
|
||||||
return iq.tag()->name();
|
return iq.tag()->name();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Parse and return the timestamp of a historic chat message and return the current time for new chat messages.
|
||||||
|
* Historic chat messages are implement as DelayedDelivers as specified in XEP-0203.
|
||||||
|
* Hence, their timestamp MUST be in UTC and conform to the DateTime format XEP-0082.
|
||||||
|
*
|
||||||
|
* @returns Seconds since the epoch.
|
||||||
|
*/
|
||||||
|
std::time_t ComputeTimestamp(const gloox::Message& msg)
|
||||||
|
{
|
||||||
|
// Only historic messages contain a timestamp!
|
||||||
|
if (!msg.when())
|
||||||
|
return std::time(nullptr);
|
||||||
|
|
||||||
|
// 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(), format, icu::Locale::getUS());
|
||||||
|
if (dateTime)
|
||||||
|
return dateTime / 1000.0;
|
||||||
|
}
|
||||||
|
|
||||||
|
return std::time(nullptr);
|
||||||
|
}
|
||||||
|
} // anonymous namespace
|
||||||
|
|
||||||
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)
|
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)
|
||||||
{
|
{
|
||||||
return new XmppClient(scriptInterface, sUsername, sPassword, sRoom, sNick, historyRequestSize, regOpt);
|
return new XmppClient(scriptInterface, sUsername, sPassword, sRoom, sNick, historyRequestSize, regOpt);
|
||||||
@@ -1300,30 +1327,6 @@ std::wstring XmppClient::GetRating(const std::string& nick)
|
|||||||
* Utilities *
|
* Utilities *
|
||||||
*****************************************************/
|
*****************************************************/
|
||||||
|
|
||||||
/**
|
|
||||||
* Parse and return the timestamp of a historic chat message and return the current time for new chat messages.
|
|
||||||
* Historic chat messages are implement as DelayedDelivers as specified in XEP-0203.
|
|
||||||
* Hence, their timestamp MUST be in UTC and conform to the DateTime format XEP-0082.
|
|
||||||
*
|
|
||||||
* @returns Seconds since the epoch.
|
|
||||||
*/
|
|
||||||
std::time_t XmppClient::ComputeTimestamp(const gloox::Message& msg)
|
|
||||||
{
|
|
||||||
// Only historic messages contain a timestamp!
|
|
||||||
if (!msg.when())
|
|
||||||
return std::time(nullptr);
|
|
||||||
|
|
||||||
// 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(), format, icu::Locale::getUS());
|
|
||||||
if (dateTime)
|
|
||||||
return dateTime / 1000.0;
|
|
||||||
}
|
|
||||||
|
|
||||||
return std::time(nullptr);
|
|
||||||
}
|
|
||||||
|
|
||||||
void XmppClient::SendStunEndpointToHost(const std::string& ip, u16 port, const std::string& hostJIDStr)
|
void XmppClient::SendStunEndpointToHost(const std::string& ip, u16 port, const std::string& hostJIDStr)
|
||||||
{
|
{
|
||||||
DbgXMPP("SendStunEndpointToHost " << hostJIDStr);
|
DbgXMPP("SendStunEndpointToHost " << hostJIDStr);
|
||||||
|
|||||||
@@ -111,11 +111,6 @@ public:
|
|||||||
|
|
||||||
void SendStunEndpointToHost(const std::string& ip, u16 port, const std::string& hostJID) override;
|
void SendStunEndpointToHost(const std::string& ip, u16 port, const std::string& hostJID) override;
|
||||||
|
|
||||||
/**
|
|
||||||
* Convert gloox values to time.
|
|
||||||
*/
|
|
||||||
static std::time_t ComputeTimestamp(const gloox::Message& msg);
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
/* Xmpp handlers */
|
/* Xmpp handlers */
|
||||||
/* MUC handlers */
|
/* MUC handlers */
|
||||||
|
|||||||
Reference in New Issue
Block a user