Falkon Develop
Cross-platform Qt-based web browser
tldextractor.h
Go to the documentation of this file.
1/* ============================================================
2* TLDExtractor, a simple Qt interface to extract TLD part of a host
3* Copyright (C) 2014 Razi Alavizadeh <s.r.alavizadeh@gmail.com>
4*
5* This program is free software: you can redistribute it and/or modify
6* it under the terms of the GNU General Public License as published by
7* the Free Software Foundation, either version 3 of the License, or
8* (at your option) any later version.
9*
10* This program is distributed in the hope that it will be useful,
11* but WITHOUT ANY WARRANTY; without even the implied warranty of
12* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13* GNU General Public License for more details.
14*
15* You should have received a copy of the GNU General Public License
16* along with this program. If not, see <http://www.gnu.org/licenses/>.
17* ============================================================ */
18#ifndef TLDEXTRACTOR_H
19#define TLDEXTRACTOR_H
20
21#define TLDExtractor_Version "1.0"
22
23#include <QHash>
24#include <QObject>
25#include <QStringList>
26
27class TLDExtractor : public QObject
28{
29 Q_OBJECT
30
31public:
32 static TLDExtractor* instance();
34
35 bool isDataLoaded();
36
37 struct HostParts {
38 QString host;
39 QString tld;
40 QString domain;
42 QString subdomain;
43 };
44
45 QString TLD(const QString &host);
46 QString domain(const QString &host);
47 QString registrableDomain(const QString &host);
48 QString subdomain(const QString &host);
49
50 HostParts splitParts(const QString &host);
51
52 QStringList dataSearchPaths() const;
53 void setDataSearchPaths(const QStringList &searchPaths = TLDExtractor::defaultDataSearchPaths());
54
55 bool test();
56
57private:
58 Q_DISABLE_COPY(TLDExtractor)
59
60 static TLDExtractor* s_instance;
61 TLDExtractor(QObject* parent = nullptr);
62
63 static QStringList defaultDataSearchPaths();
64
65 void loadData();
66 bool parseData(const QString &dataFile, bool loadPrivateDomains = false);
67
68 QString domainHelper(const QString &host, const QString &tldPart);
69 QString registrableDomainHelper(const QString &domainPart, const QString &tldPart);
70 QString subdomainHelper(const QString &host, const QString &registrablePart);
71
72 QString normalizedHost(const QString &host) const;
73
74 bool checkPublicSuffix(const QString &hostName, const QString &registrableName);
75
76 QString m_dataFileName;
77 QStringList m_dataSearchPaths;
78
79 QMultiHash<QString, QString> m_tldHash;
80};
81
82#endif // TLDEXTRACTOR_H
QString subdomain(const QString &host)
static TLDExtractor * instance()
HostParts splitParts(const QString &host)
QStringList dataSearchPaths() const
QString registrableDomain(const QString &host)
bool isDataLoaded()
QString TLD(const QString &host)
void setDataSearchPaths(const QStringList &searchPaths=TLDExtractor::defaultDataSearchPaths())
QString domain(const QString &host)