Isolate lib_base library. Use crl::time in getms.
This commit is contained in:
		
							parent
							
								
									cb371f09ac
								
							
						
					
					
						commit
						64b8adb3d0
					
				
					 23 changed files with 267 additions and 157 deletions
				
			
		| 
						 | 
				
			
			@ -25,3 +25,14 @@ inline constexpr size_t array_size(const Type(&)[Size]) {
 | 
			
		|||
}
 | 
			
		||||
 | 
			
		||||
} // namespace base
 | 
			
		||||
 | 
			
		||||
template <typename T>
 | 
			
		||||
inline void accumulate_max(T &a, const T &b) { if (a < b) a = b; }
 | 
			
		||||
 | 
			
		||||
template <typename T>
 | 
			
		||||
inline void accumulate_min(T &a, const T &b) { if (a > b) a = b; }
 | 
			
		||||
 | 
			
		||||
template <size_t Size>
 | 
			
		||||
QLatin1String qstr(const char(&string)[Size]) {
 | 
			
		||||
	return QLatin1String(string, Size - 1);
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
							
								
								
									
										9
									
								
								Telegram/SourceFiles/base/base_pch.cpp
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										9
									
								
								Telegram/SourceFiles/base/base_pch.cpp
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,9 @@
 | 
			
		|||
/*
 | 
			
		||||
This file is part of Telegram Desktop,
 | 
			
		||||
the official desktop application for the Telegram messaging service.
 | 
			
		||||
 | 
			
		||||
For license and copyright information please follow this link:
 | 
			
		||||
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
 | 
			
		||||
*/
 | 
			
		||||
#include "base/base_pch.h"
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										30
									
								
								Telegram/SourceFiles/base/base_pch.h
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										30
									
								
								Telegram/SourceFiles/base/base_pch.h
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,30 @@
 | 
			
		|||
/*
 | 
			
		||||
This file is part of Telegram Desktop,
 | 
			
		||||
the official desktop application for the Telegram messaging service.
 | 
			
		||||
 | 
			
		||||
For license and copyright information please follow this link:
 | 
			
		||||
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
 | 
			
		||||
*/
 | 
			
		||||
 | 
			
		||||
#include <QtCore/QByteArray>
 | 
			
		||||
#include <QtCore/QString>
 | 
			
		||||
#include <QtCore/QUrl>
 | 
			
		||||
#include <QtCore/QMutex>
 | 
			
		||||
#include <QtCore/QRegularExpression>
 | 
			
		||||
 | 
			
		||||
#include <crl/crl.h>
 | 
			
		||||
#include <rpl/rpl.h>
 | 
			
		||||
 | 
			
		||||
#include <vector>
 | 
			
		||||
#include <unordered_map>
 | 
			
		||||
#include <set>
 | 
			
		||||
 | 
			
		||||
#include <range/v3/all.hpp>
 | 
			
		||||
#ifdef Q_OS_WIN
 | 
			
		||||
#include "platform/win/windows_range_v3_helpers.h"
 | 
			
		||||
#endif // Q_OS_WIN
 | 
			
		||||
 | 
			
		||||
#include "base/flat_map.h"
 | 
			
		||||
#include "base/flat_set.h"
 | 
			
		||||
#include "base/optional.h"
 | 
			
		||||
#include "base/openssl_help.h"
 | 
			
		||||
| 
						 | 
				
			
			@ -21,6 +21,7 @@ public:
 | 
			
		|||
	~binary_guard();
 | 
			
		||||
 | 
			
		||||
	bool alive() const;
 | 
			
		||||
	void kill();
 | 
			
		||||
 | 
			
		||||
private:
 | 
			
		||||
	void destroy();
 | 
			
		||||
| 
						 | 
				
			
			@ -51,6 +52,10 @@ inline bool binary_guard::alive() const {
 | 
			
		|||
	return _bothAlive && _bothAlive->load();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
inline void binary_guard::kill() {
 | 
			
		||||
	destroy();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
inline void binary_guard::destroy() {
 | 
			
		||||
	if (_bothAlive) {
 | 
			
		||||
		auto old = true;
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -12,6 +12,7 @@ namespace internal {
 | 
			
		|||
namespace {
 | 
			
		||||
 | 
			
		||||
bool CantUseObservables = false;
 | 
			
		||||
void (*HandleDelayedMethod)() = nullptr;
 | 
			
		||||
 | 
			
		||||
struct ObservableListWrap {
 | 
			
		||||
	~ObservableListWrap() {
 | 
			
		||||
| 
						 | 
				
			
			@ -35,7 +36,9 @@ ObservableListWrap &ActiveObservables() {
 | 
			
		|||
void RegisterPendingObservable(ObservableCallHandlers *handlers) {
 | 
			
		||||
	if (CantUseObservables) return;
 | 
			
		||||
	PendingObservables().list.insert(handlers);
 | 
			
		||||
	Global::RefHandleObservables().call();
 | 
			
		||||
	if (HandleDelayedMethod) {
 | 
			
		||||
		HandleDelayedMethod();
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void UnregisterActiveObservable(ObservableCallHandlers *handlers) {
 | 
			
		||||
| 
						 | 
				
			
			@ -51,6 +54,10 @@ void UnregisterObservable(ObservableCallHandlers *handlers) {
 | 
			
		|||
 | 
			
		||||
} // namespace internal
 | 
			
		||||
 | 
			
		||||
void InitObservables(void(*HandleDelayed)()) {
 | 
			
		||||
	internal::HandleDelayedMethod = HandleDelayed;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void HandleObservables() {
 | 
			
		||||
	if (internal::CantUseObservables) return;
 | 
			
		||||
	auto &active = internal::ActiveObservables().list;
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -452,6 +452,7 @@ private:
 | 
			
		|||
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
void InitObservables(void(*HandleDelayed)());
 | 
			
		||||
void HandleObservables();
 | 
			
		||||
 | 
			
		||||
template <
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -10,11 +10,26 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
 | 
			
		|||
namespace qthelp {
 | 
			
		||||
namespace {
 | 
			
		||||
 | 
			
		||||
QRegularExpression RegExpProtocol() {
 | 
			
		||||
	static const auto result = QRegularExpression("^([a-zA-Z]+)://");
 | 
			
		||||
QRegularExpression CreateRegExp(const QString &expression) {
 | 
			
		||||
	auto result = QRegularExpression(
 | 
			
		||||
		expression,
 | 
			
		||||
		QRegularExpression::UseUnicodePropertiesOption);
 | 
			
		||||
#ifndef OS_MAC_OLD
 | 
			
		||||
	result.optimize();
 | 
			
		||||
#endif // OS_MAC_OLD
 | 
			
		||||
	return result;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
QString ExpressionDomain() {
 | 
			
		||||
	// Matches any domain name, containing at least one '.', including "file.txt".
 | 
			
		||||
	return QString::fromUtf8("(?<![\\w\\$\\-\\_%=\\.])(?:([a-zA-Z]+)://)?((?:[A-Za-z" "\xD0\x90-\xD0\xAF\xD0\x81" "\xD0\xB0-\xD1\x8F\xD1\x91" "0-9\\-\\_]+\\.){1,10}([A-Za-z" "\xD1\x80\xD1\x84" "\\-\\d]{2,22})(\\:\\d+)?)");
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
QString ExpressionDomainExplicit() {
 | 
			
		||||
	// Matches any domain name, containing a protocol, including "test://localhost".
 | 
			
		||||
	return QString::fromUtf8("(?<![\\w\\$\\-\\_%=\\.])(?:([a-zA-Z]+)://)((?:[A-Za-z" "\xD0\x90-\xD0\xAF\xD0\x81" "\xD0\xB0-\xD1\x8F\xD1\x91" "0-9\\-\\_]+\\.){0,10}([A-Za-z" "\xD1\x80\xD1\x84" "\\-\\d]{2,22})(\\:\\d+)?)");
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
bool IsGoodProtocol(const QString &protocol) {
 | 
			
		||||
	const auto equals = [&](QLatin1String string) {
 | 
			
		||||
		return protocol.compare(string, Qt::CaseInsensitive) == 0;
 | 
			
		||||
| 
						 | 
				
			
			@ -26,6 +41,21 @@ bool IsGoodProtocol(const QString &protocol) {
 | 
			
		|||
 | 
			
		||||
} // namespace
 | 
			
		||||
 | 
			
		||||
const QRegularExpression &RegExpDomain() {
 | 
			
		||||
	static const auto result = CreateRegExp(ExpressionDomain());
 | 
			
		||||
	return result;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
const QRegularExpression &RegExpDomainExplicit() {
 | 
			
		||||
	static const auto result = CreateRegExp(ExpressionDomainExplicit());
 | 
			
		||||
	return result;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
QRegularExpression RegExpProtocol() {
 | 
			
		||||
	static const auto result = CreateRegExp("^([a-zA-Z]+)://");
 | 
			
		||||
	return result;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
QMap<QString, QString> url_parse_params(
 | 
			
		||||
		const QString ¶ms,
 | 
			
		||||
		UrlParamNameTransform transform) {
 | 
			
		||||
| 
						 | 
				
			
			@ -77,9 +107,9 @@ QString validate_url(const QString &value) {
 | 
			
		|||
	if (trimmed.isEmpty()) {
 | 
			
		||||
		return QString();
 | 
			
		||||
	}
 | 
			
		||||
	const auto match = TextUtilities::RegExpDomainExplicit().match(trimmed);
 | 
			
		||||
	const auto match = RegExpDomainExplicit().match(trimmed);
 | 
			
		||||
	if (!match.hasMatch()) {
 | 
			
		||||
		const auto domain = TextUtilities::RegExpDomain().match(trimmed);
 | 
			
		||||
		const auto domain = RegExpDomain().match(trimmed);
 | 
			
		||||
		if (!domain.hasMatch() || domain.capturedStart() != 0) {
 | 
			
		||||
			return QString();
 | 
			
		||||
		}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -9,6 +9,10 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
 | 
			
		|||
 | 
			
		||||
namespace qthelp {
 | 
			
		||||
 | 
			
		||||
const QRegularExpression &RegExpDomain();
 | 
			
		||||
const QRegularExpression &RegExpDomainExplicit();
 | 
			
		||||
QRegularExpression RegExpProtocol();
 | 
			
		||||
 | 
			
		||||
inline QString url_encode(const QString &part) {
 | 
			
		||||
	return QString::fromLatin1(QUrl::toPercentEncoding(part));
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -8,27 +8,21 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
 | 
			
		|||
#include "base/runtime_composer.h"
 | 
			
		||||
 | 
			
		||||
struct RuntimeComposerMetadatasMap {
 | 
			
		||||
	QMap<uint64, RuntimeComposerMetadata*> data;
 | 
			
		||||
	~RuntimeComposerMetadatasMap() {
 | 
			
		||||
		for_const (const RuntimeComposerMetadata *p, data) {
 | 
			
		||||
			delete p;
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
	std::map<uint64, std::unique_ptr<RuntimeComposerMetadata>> data;
 | 
			
		||||
	QMutex mutex;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
const RuntimeComposerMetadata *GetRuntimeComposerMetadata(uint64 mask) {
 | 
			
		||||
	static RuntimeComposerMetadatasMap RuntimeComposerMetadatas;
 | 
			
		||||
	static QMutex RuntimeComposerMetadatasMutex;
 | 
			
		||||
 | 
			
		||||
	QMutexLocker lock(&RuntimeComposerMetadatasMutex);
 | 
			
		||||
	auto i = RuntimeComposerMetadatas.data.constFind(mask);
 | 
			
		||||
	if (i == RuntimeComposerMetadatas.data.cend()) {
 | 
			
		||||
		RuntimeComposerMetadata *meta = new RuntimeComposerMetadata(mask);
 | 
			
		||||
		Assert(meta != nullptr);
 | 
			
		||||
 | 
			
		||||
		i = RuntimeComposerMetadatas.data.insert(mask, meta);
 | 
			
		||||
	QMutexLocker lock(&RuntimeComposerMetadatas.mutex);
 | 
			
		||||
	auto i = RuntimeComposerMetadatas.data.find(mask);
 | 
			
		||||
	if (i == end(RuntimeComposerMetadatas.data)) {
 | 
			
		||||
		i = RuntimeComposerMetadatas.data.emplace(
 | 
			
		||||
			mask,
 | 
			
		||||
			std::make_unique<RuntimeComposerMetadata>(mask)).first;
 | 
			
		||||
	}
 | 
			
		||||
	return i.value();
 | 
			
		||||
	return i->second.get();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
const RuntimeComposerMetadata *RuntimeComposerBase::ZeroRuntimeComposerMetadata = GetRuntimeComposerMetadata(0);
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -7,6 +7,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
 | 
			
		|||
*/
 | 
			
		||||
#include "base/timer.h"
 | 
			
		||||
 | 
			
		||||
#include <QtCore/QTimerEvent>
 | 
			
		||||
 | 
			
		||||
namespace base {
 | 
			
		||||
namespace {
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -48,7 +50,7 @@ void Timer::start(TimeMs timeout, Qt::TimerType type, Repeat repeat) {
 | 
			
		|||
	setTimeout(timeout);
 | 
			
		||||
	_timerId = startTimer(_timeout, _type);
 | 
			
		||||
	if (_timerId) {
 | 
			
		||||
		_next = getms(true) + _timeout;
 | 
			
		||||
		_next = crl::time() + _timeout;
 | 
			
		||||
	} else {
 | 
			
		||||
		_next = 0;
 | 
			
		||||
	}
 | 
			
		||||
| 
						 | 
				
			
			@ -64,7 +66,7 @@ TimeMs Timer::remainingTime() const {
 | 
			
		|||
	if (!isActive()) {
 | 
			
		||||
		return -1;
 | 
			
		||||
	}
 | 
			
		||||
	auto now = getms(true);
 | 
			
		||||
	auto now = crl::time();
 | 
			
		||||
	return (_next > now) ? (_next - now) : TimeMs(0);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -101,7 +103,7 @@ void Timer::timerEvent(QTimerEvent *e) {
 | 
			
		|||
		if (_adjusted) {
 | 
			
		||||
			start(_timeout, _type, repeat());
 | 
			
		||||
		} else {
 | 
			
		||||
			_next = getms(true) + _timeout;
 | 
			
		||||
			_next = crl::time() + _timeout;
 | 
			
		||||
		}
 | 
			
		||||
	} else {
 | 
			
		||||
		cancel();
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -74,7 +74,7 @@ private:
 | 
			
		|||
};
 | 
			
		||||
 | 
			
		||||
//bool ValidateUrl(const QString &value) {
 | 
			
		||||
//	const auto match = TextUtilities::RegExpDomain().match(value);
 | 
			
		||||
//	const auto match = qthelp::RegExpDomain().match(value);
 | 
			
		||||
//	if (!match.hasMatch() || match.capturedStart() != 0) {
 | 
			
		||||
//		return false;
 | 
			
		||||
//	}
 | 
			
		||||
| 
						 | 
				
			
			@ -596,7 +596,7 @@ void MessageLinksParser::parse() {
 | 
			
		|||
	const auto len = text.size();
 | 
			
		||||
	const QChar *start = text.unicode(), *end = start + text.size();
 | 
			
		||||
	for (auto offset = 0, matchOffset = offset; offset < len;) {
 | 
			
		||||
		auto m = TextUtilities::RegExpDomain().match(text, matchOffset);
 | 
			
		||||
		auto m = qthelp::RegExpDomain().match(text, matchOffset);
 | 
			
		||||
		if (!m.hasMatch()) break;
 | 
			
		||||
 | 
			
		||||
		auto domainOffset = m.capturedStart();
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -47,11 +47,17 @@ void ProcessMainQueue(void (*callable)(void*), void *argument) {
 | 
			
		|||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void ProcessObservables() {
 | 
			
		||||
	Global::RefHandleObservables().call();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
} // namespace
 | 
			
		||||
 | 
			
		||||
MainQueueProcessor::MainQueueProcessor() {
 | 
			
		||||
	acquire();
 | 
			
		||||
	crl::init_main_queue(ProcessMainQueue);
 | 
			
		||||
 | 
			
		||||
	base::InitObservables(ProcessObservables);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
bool MainQueueProcessor::event(QEvent *event) {
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -194,52 +194,34 @@ namespace {
 | 
			
		|||
		return 0;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	float64 _msFreq;
 | 
			
		||||
	float64 _msgIdCoef;
 | 
			
		||||
	TimeMs _msStart = 0, _msAddToMsStart = 0, _msAddToUnixtime = 0;
 | 
			
		||||
	int32 _timeStart = 0;
 | 
			
		||||
 | 
			
		||||
	class _MsInitializer {
 | 
			
		||||
	class _MsStarter {
 | 
			
		||||
	public:
 | 
			
		||||
		_MsInitializer() {
 | 
			
		||||
		_MsStarter() {
 | 
			
		||||
#ifdef Q_OS_WIN
 | 
			
		||||
			LARGE_INTEGER li;
 | 
			
		||||
			QueryPerformanceFrequency(&li);
 | 
			
		||||
            _msFreq = 1000. / float64(li.QuadPart);
 | 
			
		||||
 | 
			
		||||
			// 0xFFFF0000L istead of 0x100000000L to make msgId grow slightly slower, than unixtime and we had time to reconfigure
 | 
			
		||||
			_msgIdCoef = float64(0xFFFF0000L) / float64(li.QuadPart);
 | 
			
		||||
 | 
			
		||||
			QueryPerformanceCounter(&li);
 | 
			
		||||
			_msStart = li.QuadPart;
 | 
			
		||||
			const auto seed = li.QuadPart;
 | 
			
		||||
#elif defined Q_OS_MAC
 | 
			
		||||
            mach_timebase_info_data_t tb = { 0, 0 };
 | 
			
		||||
            mach_timebase_info(&tb);
 | 
			
		||||
            _msFreq = (float64(tb.numer) / tb.denom) / 1000000.;
 | 
			
		||||
            const auto freq = (float64(tb.numer) / tb.denom) / 1000000.;
 | 
			
		||||
            _msgIdCoef = freq * (float64(0xFFFF0000L) / 1000.);
 | 
			
		||||
 | 
			
		||||
            _msgIdCoef = _msFreq * (float64(0xFFFF0000L) / 1000.);
 | 
			
		||||
 | 
			
		||||
            _msStart = mach_absolute_time();
 | 
			
		||||
            const auto seed = mach_absolute_time();
 | 
			
		||||
#else
 | 
			
		||||
            timespec ts;
 | 
			
		||||
            clock_gettime(CLOCK_MONOTONIC, &ts);
 | 
			
		||||
            //_msFreq = 1 / 1000000.;
 | 
			
		||||
            _msgIdCoef = float64(0xFFFF0000L) / 1000000000.;
 | 
			
		||||
            _msStart = 1000LL * static_cast<TimeMs>(ts.tv_sec) + (static_cast<TimeMs>(ts.tv_nsec) / 1000000LL);
 | 
			
		||||
			_msgIdCoef = float64(0xFFFF0000L) / 1000000000.;
 | 
			
		||||
 | 
			
		||||
			timespec ts;
 | 
			
		||||
			clock_gettime(CLOCK_MONOTONIC, &ts);
 | 
			
		||||
			const auto seed = 1000LL * static_cast<TimeMs>(ts.tv_sec) + (static_cast<TimeMs>(ts.tv_nsec) / 1000000LL);
 | 
			
		||||
#endif
 | 
			
		||||
			_timeStart = LocalUnixtime();
 | 
			
		||||
			srand((uint32)(_msStart & 0xFFFFFFFFL));
 | 
			
		||||
		}
 | 
			
		||||
	};
 | 
			
		||||
 | 
			
		||||
	void _msInitialize() {
 | 
			
		||||
		static _MsInitializer _msInitializer;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	class _MsStarter {
 | 
			
		||||
	public:
 | 
			
		||||
		_MsStarter() {
 | 
			
		||||
			getms();
 | 
			
		||||
			srand((uint32)(seed & 0xFFFFFFFFL));
 | 
			
		||||
		}
 | 
			
		||||
	};
 | 
			
		||||
	_MsStarter _msStarter;
 | 
			
		||||
| 
						 | 
				
			
			@ -365,11 +347,25 @@ namespace ThirdParty {
 | 
			
		|||
		Platform::ThirdParty::start();
 | 
			
		||||
 | 
			
		||||
		if (!RAND_status()) { // should be always inited in all modern OS
 | 
			
		||||
			char buf[16];
 | 
			
		||||
			memcpy(buf, &_msStart, 8);
 | 
			
		||||
			memcpy(buf + 8, &_msFreq, 8);
 | 
			
		||||
			uchar sha256Buffer[32];
 | 
			
		||||
			RAND_seed(hashSha256(buf, 16, sha256Buffer), 32);
 | 
			
		||||
			const auto FeedSeed = [](auto value) {
 | 
			
		||||
				RAND_seed(&value, sizeof(value));
 | 
			
		||||
			};
 | 
			
		||||
#ifdef Q_OS_WIN
 | 
			
		||||
			LARGE_INTEGER li;
 | 
			
		||||
			QueryPerformanceFrequency(&li);
 | 
			
		||||
			FeedSeed(li.QuadPart);
 | 
			
		||||
			QueryPerformanceCounter(&li);
 | 
			
		||||
			FeedSeed(li.QuadPart);
 | 
			
		||||
#elif defined Q_OS_MAC
 | 
			
		||||
			mach_timebase_info_data_t tb = { 0 };
 | 
			
		||||
			mach_timebase_info(&tb);
 | 
			
		||||
			FeedSeed(tb);
 | 
			
		||||
			FeedSeed(mach_absolute_time());
 | 
			
		||||
#else
 | 
			
		||||
			timespec ts = { 0 };
 | 
			
		||||
			clock_gettime(CLOCK_MONOTONIC, &ts);
 | 
			
		||||
			FeedSeed(ts);
 | 
			
		||||
#endif
 | 
			
		||||
			if (!RAND_status()) {
 | 
			
		||||
				LOG(("MTP Error: Could not init OpenSSL rand, RAND_status() is 0..."));
 | 
			
		||||
			}
 | 
			
		||||
| 
						 | 
				
			
			@ -429,12 +425,7 @@ namespace ThirdParty {
 | 
			
		|||
}
 | 
			
		||||
 | 
			
		||||
bool checkms() {
 | 
			
		||||
	auto unixms = (LocalUnixtime() - _timeStart) * 1000LL + _msAddToUnixtime;
 | 
			
		||||
	auto ms = getms(true);
 | 
			
		||||
	if (ms > unixms + 1000LL) {
 | 
			
		||||
		_msAddToUnixtime = ((ms - unixms) / 1000LL) * 1000LL;
 | 
			
		||||
	} else if (unixms > ms + 1000LL) {
 | 
			
		||||
		_msAddToMsStart += ((unixms - ms) / 1000LL) * 1000LL;
 | 
			
		||||
	if (crl::adjust_time()) {
 | 
			
		||||
		Sandbox::adjustSingleTimers();
 | 
			
		||||
		return true;
 | 
			
		||||
	}
 | 
			
		||||
| 
						 | 
				
			
			@ -442,24 +433,7 @@ bool checkms() {
 | 
			
		|||
}
 | 
			
		||||
 | 
			
		||||
TimeMs getms(bool checked) {
 | 
			
		||||
    _msInitialize();
 | 
			
		||||
#ifdef Q_OS_WIN
 | 
			
		||||
    LARGE_INTEGER li;
 | 
			
		||||
    QueryPerformanceCounter(&li);
 | 
			
		||||
	return ((li.QuadPart - _msStart) * _msFreq) + (checked ? _msAddToMsStart : 0LL);
 | 
			
		||||
#elif defined Q_OS_MAC
 | 
			
		||||
	auto msCount = static_cast<TimeMs>(mach_absolute_time());
 | 
			
		||||
	return ((msCount - _msStart) * _msFreq) + (checked ? _msAddToMsStart : 0LL);
 | 
			
		||||
#else
 | 
			
		||||
    timespec ts;
 | 
			
		||||
    auto res = clock_gettime(CLOCK_MONOTONIC, &ts);
 | 
			
		||||
    if (res != 0) {
 | 
			
		||||
        LOG(("Bad clock_gettime result: %1").arg(res));
 | 
			
		||||
        return 0;
 | 
			
		||||
    }
 | 
			
		||||
    auto msCount = 1000LL * static_cast<TimeMs>(ts.tv_sec) + (static_cast<TimeMs>(ts.tv_nsec) / 1000000LL);
 | 
			
		||||
    return (msCount - _msStart) + (checked ? _msAddToMsStart : 0LL);
 | 
			
		||||
#endif
 | 
			
		||||
	return crl::time();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
uint64 msgid() {
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -22,7 +22,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
 | 
			
		|||
#include <set>
 | 
			
		||||
 | 
			
		||||
#define qsl(s) QStringLiteral(s)
 | 
			
		||||
#define qstr(s) QLatin1String((s), sizeof(s) - 1)
 | 
			
		||||
 | 
			
		||||
// Define specializations for QByteArray for Qt 5.3.2, because
 | 
			
		||||
// QByteArray in Qt 5.3.2 doesn't declare "pointer" subtype.
 | 
			
		||||
| 
						 | 
				
			
			@ -186,12 +185,6 @@ inline QByteArray str_const_toByteArray(const str_const &str) {
 | 
			
		|||
	return QByteArray::fromRawData(str.c_str(), str.size());
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
template <typename T>
 | 
			
		||||
inline void accumulate_max(T &a, const T &b) { if (a < b) a = b; }
 | 
			
		||||
 | 
			
		||||
template <typename T>
 | 
			
		||||
inline void accumulate_min(T &a, const T &b) { if (a > b) a = b; }
 | 
			
		||||
 | 
			
		||||
void unixtimeInit();
 | 
			
		||||
void unixtimeSet(TimeId serverTime, bool force = false);
 | 
			
		||||
TimeId unixtime();
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -668,7 +668,8 @@ void Messenger::forceLogOut(const TextWithEntities &explanation) {
 | 
			
		|||
}
 | 
			
		||||
 | 
			
		||||
void Messenger::checkLocalTime() {
 | 
			
		||||
	if (App::main()) App::main()->checkLastUpdate(checkms());
 | 
			
		||||
	const auto updated = checkms();
 | 
			
		||||
	if (App::main()) App::main()->checkLastUpdate(updated);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void Messenger::onAppStateChanged(Qt::ApplicationState state) {
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -9,20 +9,11 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
 | 
			
		|||
 | 
			
		||||
#include "auth_session.h"
 | 
			
		||||
#include "lang/lang_tag.h"
 | 
			
		||||
#include "base/qthelp_url.h"
 | 
			
		||||
 | 
			
		||||
namespace TextUtilities {
 | 
			
		||||
namespace {
 | 
			
		||||
 | 
			
		||||
QString ExpressionDomain() {
 | 
			
		||||
	// Matches any domain name, containing at least one '.', including "file.txt".
 | 
			
		||||
	return QString::fromUtf8("(?<![\\w\\$\\-\\_%=\\.])(?:([a-zA-Z]+)://)?((?:[A-Za-z" "\xD0\x90-\xD0\xAF\xD0\x81" "\xD0\xB0-\xD1\x8F\xD1\x91" "0-9\\-\\_]+\\.){1,10}([A-Za-z" "\xD1\x80\xD1\x84" "\\-\\d]{2,22})(\\:\\d+)?)");
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
QString ExpressionDomainExplicit() {
 | 
			
		||||
	// Matches any domain name, containing a protocol, including "test://localhost".
 | 
			
		||||
	return QString::fromUtf8("(?<![\\w\\$\\-\\_%=\\.])(?:([a-zA-Z]+)://)((?:[A-Za-z" "\xD0\x90-\xD0\xAF\xD0\x81" "\xD0\xB0-\xD1\x8F\xD1\x91" "0-9\\-\\_]+\\.){0,10}([A-Za-z" "\xD1\x80\xD1\x84" "\\-\\d]{2,22})(\\:\\d+)?)");
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
QString ExpressionMailNameAtEnd() {
 | 
			
		||||
	// Matches email first part (before '@') at the end of the string.
 | 
			
		||||
	// First we find a domain without protocol (like "gmail.com"), then
 | 
			
		||||
| 
						 | 
				
			
			@ -1138,16 +1129,6 @@ const QRegularExpression &RegExpWordSplit() {
 | 
			
		|||
 | 
			
		||||
} // namespace
 | 
			
		||||
 | 
			
		||||
const QRegularExpression &RegExpDomain() {
 | 
			
		||||
	static const auto result = CreateRegExp(ExpressionDomain());
 | 
			
		||||
	return result;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
const QRegularExpression &RegExpDomainExplicit() {
 | 
			
		||||
	static const auto result = CreateRegExp(ExpressionDomainExplicit());
 | 
			
		||||
	return result;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
const QRegularExpression &RegExpMailNameAtEnd() {
 | 
			
		||||
	static const auto result = CreateRegExp(ExpressionMailNameAtEnd());
 | 
			
		||||
	return result;
 | 
			
		||||
| 
						 | 
				
			
			@ -1604,8 +1585,8 @@ void ParseEntities(TextWithEntities &result, int32 flags, bool rich) {
 | 
			
		|||
				}
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
		auto mDomain = RegExpDomain().match(result.text, matchOffset);
 | 
			
		||||
		auto mExplicitDomain = RegExpDomainExplicit().match(result.text, matchOffset);
 | 
			
		||||
		auto mDomain = qthelp::RegExpDomain().match(result.text, matchOffset);
 | 
			
		||||
		auto mExplicitDomain = qthelp::RegExpDomainExplicit().match(result.text, matchOffset);
 | 
			
		||||
		auto mHashtag = withHashtags ? RegExpHashtag().match(result.text, matchOffset) : QRegularExpressionMatch();
 | 
			
		||||
		auto mMention = withMentions ? RegExpMention().match(result.text, qMax(mentionSkip, matchOffset)) : QRegularExpressionMatch();
 | 
			
		||||
		auto mBotCommand = withBotCommands ? RegExpBotCommand().match(result.text, matchOffset) : QRegularExpressionMatch();
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -157,8 +157,6 @@ namespace TextUtilities {
 | 
			
		|||
bool IsValidProtocol(const QString &protocol);
 | 
			
		||||
bool IsValidTopDomain(const QString &domain);
 | 
			
		||||
 | 
			
		||||
const QRegularExpression &RegExpDomain();
 | 
			
		||||
const QRegularExpression &RegExpDomainExplicit();
 | 
			
		||||
const QRegularExpression &RegExpMailNameAtEnd();
 | 
			
		||||
const QRegularExpression &RegExpHashtag();
 | 
			
		||||
const QRegularExpression &RegExpHashtagExclude();
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
							
								
								
									
										2
									
								
								Telegram/ThirdParty/crl
									
										
									
									
										vendored
									
									
								
							
							
						
						
									
										2
									
								
								Telegram/ThirdParty/crl
									
										
									
									
										vendored
									
									
								
							| 
						 | 
				
			
			@ -1 +1 @@
 | 
			
		|||
Subproject commit 527ad273b683d52c5adf5b45b73c6466aa0d0cf0
 | 
			
		||||
Subproject commit 2cab11076d84a9db7d86f165eb2cfb4c6ebcc8f4
 | 
			
		||||
| 
						 | 
				
			
			@ -78,6 +78,7 @@
 | 
			
		|||
      'utils.gyp:Updater',
 | 
			
		||||
      '../ThirdParty/libtgvoip/libtgvoip.gyp:libtgvoip',
 | 
			
		||||
      'crl.gyp:crl',
 | 
			
		||||
      'lib_base.gyp:lib_base',
 | 
			
		||||
      'lib_export.gyp:lib_export',
 | 
			
		||||
      'lib_storage.gyp:lib_storage',
 | 
			
		||||
    ],
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -53,6 +53,8 @@
 | 
			
		|||
      '<(crl_src_loc)/dispatch/crl_dispatch_queue.h',
 | 
			
		||||
      '<(crl_src_loc)/dispatch/crl_dispatch_semaphore.cpp',
 | 
			
		||||
      '<(crl_src_loc)/dispatch/crl_dispatch_semaphore.h',
 | 
			
		||||
      '<(crl_src_loc)/mac/crl_mac_time.cpp',
 | 
			
		||||
      '<(crl_src_loc)/linux/crl_linux_time.cpp',
 | 
			
		||||
      '<(crl_src_loc)/qt/crl_qt_async.cpp',
 | 
			
		||||
      '<(crl_src_loc)/qt/crl_qt_async.h',
 | 
			
		||||
      '<(crl_src_loc)/qt/crl_qt_semaphore.cpp',
 | 
			
		||||
| 
						 | 
				
			
			@ -64,12 +66,15 @@
 | 
			
		|||
      '<(crl_src_loc)/winapi/crl_winapi_list.h',
 | 
			
		||||
      '<(crl_src_loc)/winapi/crl_winapi_semaphore.cpp',
 | 
			
		||||
      '<(crl_src_loc)/winapi/crl_winapi_semaphore.h',
 | 
			
		||||
      '<(crl_src_loc)/winapi/crl_winapi_time.cpp',
 | 
			
		||||
      '<(crl_src_loc)/crl.h',
 | 
			
		||||
      '<(crl_src_loc)/crl_async.h',
 | 
			
		||||
      '<(crl_src_loc)/crl_object_on_queue.h',
 | 
			
		||||
      '<(crl_src_loc)/crl_on_main.h',
 | 
			
		||||
      '<(crl_src_loc)/crl_queue.h',
 | 
			
		||||
      '<(crl_src_loc)/crl_semaphore.h',
 | 
			
		||||
      '<(crl_src_loc)/crl_time.cpp',
 | 
			
		||||
      '<(crl_src_loc)/crl_time.h',
 | 
			
		||||
    ],
 | 
			
		||||
  }],
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
							
								
								
									
										95
									
								
								Telegram/gyp/lib_base.gyp
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										95
									
								
								Telegram/gyp/lib_base.gyp
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,95 @@
 | 
			
		|||
# This file is part of Telegram Desktop,
 | 
			
		||||
# the official desktop application for the Telegram messaging service.
 | 
			
		||||
#
 | 
			
		||||
# For license and copyright information please follow this link:
 | 
			
		||||
# https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
 | 
			
		||||
 | 
			
		||||
{
 | 
			
		||||
  'includes': [
 | 
			
		||||
    'common.gypi',
 | 
			
		||||
  ],
 | 
			
		||||
  'targets': [{
 | 
			
		||||
    'target_name': 'lib_base',
 | 
			
		||||
    'type': 'static_library',
 | 
			
		||||
    'includes': [
 | 
			
		||||
      'common.gypi',
 | 
			
		||||
	  'openssl.gypi',
 | 
			
		||||
      'qt.gypi',
 | 
			
		||||
      'telegram_win.gypi',
 | 
			
		||||
      'telegram_mac.gypi',
 | 
			
		||||
      'telegram_linux.gypi',
 | 
			
		||||
      'pch.gypi',
 | 
			
		||||
    ],
 | 
			
		||||
    'variables': {
 | 
			
		||||
      'src_loc': '../SourceFiles',
 | 
			
		||||
      'res_loc': '../Resources',
 | 
			
		||||
      'libs_loc': '../../../Libraries',
 | 
			
		||||
      'official_build_target%': '',
 | 
			
		||||
      'submodules_loc': '../ThirdParty',
 | 
			
		||||
      'pch_source': '<(src_loc)/base/base_pch.cpp',
 | 
			
		||||
      'pch_header': '<(src_loc)/base/base_pch.h',
 | 
			
		||||
    },
 | 
			
		||||
    'defines': [
 | 
			
		||||
      'XXH_INLINE_ALL',
 | 
			
		||||
    ],
 | 
			
		||||
    'dependencies': [
 | 
			
		||||
      'crl.gyp:crl',
 | 
			
		||||
    ],
 | 
			
		||||
    'include_dirs': [
 | 
			
		||||
      '<(src_loc)',
 | 
			
		||||
      '<(SHARED_INTERMEDIATE_DIR)',
 | 
			
		||||
      '<(libs_loc)/range-v3/include',
 | 
			
		||||
      '<(submodules_loc)/GSL/include',
 | 
			
		||||
      '<(submodules_loc)/variant/include',
 | 
			
		||||
      '<(submodules_loc)/crl/src',
 | 
			
		||||
      '<(submodules_loc)/xxHash',
 | 
			
		||||
    ],
 | 
			
		||||
    'sources': [
 | 
			
		||||
      '<(src_loc)/base/algorithm.h',
 | 
			
		||||
      '<(src_loc)/base/assertion.h',
 | 
			
		||||
      '<(src_loc)/base/basic_types.h',
 | 
			
		||||
      '<(src_loc)/base/binary_guard.h',
 | 
			
		||||
      '<(src_loc)/base/build_config.h',
 | 
			
		||||
      '<(src_loc)/base/bytes.h',
 | 
			
		||||
      '<(src_loc)/base/flags.h',
 | 
			
		||||
      '<(src_loc)/base/enum_mask.h',
 | 
			
		||||
      '<(src_loc)/base/flat_map.h',
 | 
			
		||||
      '<(src_loc)/base/flat_set.h',
 | 
			
		||||
      '<(src_loc)/base/functors.h',
 | 
			
		||||
      '<(src_loc)/base/index_based_iterator.h',
 | 
			
		||||
      '<(src_loc)/base/match_method.h',
 | 
			
		||||
      '<(src_loc)/base/observer.cpp',
 | 
			
		||||
      '<(src_loc)/base/observer.h',
 | 
			
		||||
      '<(src_loc)/base/ordered_set.h',
 | 
			
		||||
      '<(src_loc)/base/openssl_help.h',
 | 
			
		||||
      '<(src_loc)/base/optional.h',
 | 
			
		||||
      '<(src_loc)/base/overload.h',
 | 
			
		||||
      '<(src_loc)/base/parse_helper.cpp',
 | 
			
		||||
      '<(src_loc)/base/parse_helper.h',
 | 
			
		||||
      '<(src_loc)/base/qthelp_regex.h',
 | 
			
		||||
      '<(src_loc)/base/qthelp_url.cpp',
 | 
			
		||||
      '<(src_loc)/base/qthelp_url.h',
 | 
			
		||||
      '<(src_loc)/base/runtime_composer.cpp',
 | 
			
		||||
      '<(src_loc)/base/runtime_composer.h',
 | 
			
		||||
      '<(src_loc)/base/timer.cpp',
 | 
			
		||||
      '<(src_loc)/base/timer.h',
 | 
			
		||||
      '<(src_loc)/base/type_traits.h',
 | 
			
		||||
      '<(src_loc)/base/unique_any.h',
 | 
			
		||||
      '<(src_loc)/base/unique_function.h',
 | 
			
		||||
      '<(src_loc)/base/unique_qptr.h',
 | 
			
		||||
      '<(src_loc)/base/value_ordering.h',
 | 
			
		||||
      '<(src_loc)/base/variant.h',
 | 
			
		||||
      '<(src_loc)/base/virtual_method.h',
 | 
			
		||||
      '<(src_loc)/base/weak_ptr.h',
 | 
			
		||||
      '<(src_loc)/base/zlib_help.h',
 | 
			
		||||
    ],
 | 
			
		||||
    'conditions': [[ 'build_macold', {
 | 
			
		||||
      'xcode_settings': {
 | 
			
		||||
        'OTHER_CPLUSPLUSFLAGS': [ '-nostdinc++' ],
 | 
			
		||||
      },
 | 
			
		||||
      'include_dirs': [
 | 
			
		||||
        '/usr/local/macold/include/c++/v1',
 | 
			
		||||
      ],
 | 
			
		||||
    }]],
 | 
			
		||||
  }],
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -1,40 +1,3 @@
 | 
			
		|||
<(src_loc)/base/algorithm.h
 | 
			
		||||
<(src_loc)/base/assertion.h
 | 
			
		||||
<(src_loc)/base/basic_types.h
 | 
			
		||||
<(src_loc)/base/binary_guard.h
 | 
			
		||||
<(src_loc)/base/build_config.h
 | 
			
		||||
<(src_loc)/base/bytes.h
 | 
			
		||||
<(src_loc)/base/flags.h
 | 
			
		||||
<(src_loc)/base/enum_mask.h
 | 
			
		||||
<(src_loc)/base/flat_map.h
 | 
			
		||||
<(src_loc)/base/flat_set.h
 | 
			
		||||
<(src_loc)/base/functors.h
 | 
			
		||||
<(src_loc)/base/index_based_iterator.h
 | 
			
		||||
<(src_loc)/base/match_method.h
 | 
			
		||||
<(src_loc)/base/observer.cpp
 | 
			
		||||
<(src_loc)/base/observer.h
 | 
			
		||||
<(src_loc)/base/ordered_set.h
 | 
			
		||||
<(src_loc)/base/openssl_help.h
 | 
			
		||||
<(src_loc)/base/optional.h
 | 
			
		||||
<(src_loc)/base/overload.h
 | 
			
		||||
<(src_loc)/base/parse_helper.cpp
 | 
			
		||||
<(src_loc)/base/parse_helper.h
 | 
			
		||||
<(src_loc)/base/qthelp_regex.h
 | 
			
		||||
<(src_loc)/base/qthelp_url.cpp
 | 
			
		||||
<(src_loc)/base/qthelp_url.h
 | 
			
		||||
<(src_loc)/base/runtime_composer.cpp
 | 
			
		||||
<(src_loc)/base/runtime_composer.h
 | 
			
		||||
<(src_loc)/base/timer.cpp
 | 
			
		||||
<(src_loc)/base/timer.h
 | 
			
		||||
<(src_loc)/base/type_traits.h
 | 
			
		||||
<(src_loc)/base/unique_any.h
 | 
			
		||||
<(src_loc)/base/unique_function.h
 | 
			
		||||
<(src_loc)/base/unique_qptr.h
 | 
			
		||||
<(src_loc)/base/value_ordering.h
 | 
			
		||||
<(src_loc)/base/variant.h
 | 
			
		||||
<(src_loc)/base/virtual_method.h
 | 
			
		||||
<(src_loc)/base/weak_ptr.h
 | 
			
		||||
<(src_loc)/base/zlib_help.h
 | 
			
		||||
<(src_loc)/boxes/peers/edit_peer_info_box.cpp
 | 
			
		||||
<(src_loc)/boxes/peers/edit_peer_info_box.h
 | 
			
		||||
<(src_loc)/boxes/peers/manage_peer_box.cpp
 | 
			
		||||
| 
						 | 
				
			
			@ -811,6 +774,9 @@ platforms: !win
 | 
			
		|||
<(minizip_loc)/unzip.c
 | 
			
		||||
<(minizip_loc)/unzip.h
 | 
			
		||||
 | 
			
		||||
platforms: win
 | 
			
		||||
<(res_loc)/winrc/Telegram.rc
 | 
			
		||||
 | 
			
		||||
platforms: mac
 | 
			
		||||
<(sp_media_key_tap_loc)/SPMediaKeyTap.m
 | 
			
		||||
<(sp_media_key_tap_loc)/SPMediaKeyTap.h
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -7,9 +7,6 @@
 | 
			
		|||
{
 | 
			
		||||
  'conditions': [[ 'build_win', {
 | 
			
		||||
    'msbuild_toolset': 'v141',
 | 
			
		||||
    'sources': [
 | 
			
		||||
      '<(res_loc)/winrc/Telegram.rc',
 | 
			
		||||
    ],
 | 
			
		||||
    'library_dirs': [
 | 
			
		||||
      '<(libs_loc)/ffmpeg',
 | 
			
		||||
    ],
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		
		Reference in a new issue