2014-11-08 05:45:21 +08:00
/*
2015-06-06 09:40:08 +08:00
Copyright © 2014 - 2015 by The qTox Project
2014-11-08 05:45:21 +08:00
This file is part of qTox , a Qt - based graphical interface for Tox .
2015-06-06 09:40:08 +08:00
qTox is libre software : you can redistribute it and / or modify
2014-11-08 05:45:21 +08:00
it under the terms of the GNU General Public License as published by
the Free Software Foundation , either version 3 of the License , or
( at your option ) any later version .
2015-06-06 09:40:08 +08:00
qTox is distributed in the hope that it will be useful ,
2014-11-08 05:45:21 +08:00
but WITHOUT ANY WARRANTY ; without even the implied warranty of
2015-06-06 09:40:08 +08:00
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
GNU General Public License for more details .
2014-11-08 05:45:21 +08:00
2015-06-06 09:40:08 +08:00
You should have received a copy of the GNU General Public License
along with qTox . If not , see < http : //www.gnu.org/licenses/>.
2014-11-08 05:45:21 +08:00
*/
2014-11-06 22:12:10 +08:00
# ifndef QTOXDNS_H
# define QTOXDNS_H
2015-06-06 07:44:47 +08:00
# include "src/core/corestructs.h"
# include "src/core/toxid.h"
2014-11-06 22:12:10 +08:00
# include <QDnsLookup>
# include <QObject>
2014-11-11 06:55:13 +08:00
/// Tox1 is not encrypted, it's unsafe
# define TOX1_SILENT_FALLBACK 0
2015-01-05 04:02:24 +08:00
/// That said if the user insists ...
# define TOX1_ASK_FALLBACK 1
2014-11-06 22:12:10 +08:00
/// Handles tox1 and tox3 DNS queries
class ToxDNS : public QObject
{
2014-11-09 20:14:21 +08:00
Q_OBJECT
2014-11-06 22:12:10 +08:00
public :
struct tox3_server ///< Represents a tox3 server
{
tox3_server ( ) = default ;
tox3_server ( const char * _name , uint8_t _pk [ 32 ] ) : name { _name } , pubkey { _pk } { }
const char * name ; ///< Hostname of the server, e.g. toxme.se
uint8_t * pubkey ; ///< Public key of the tox3 server, usually 256bit long
} ;
public :
2015-05-24 02:58:41 +08:00
/// Tries to map a text string to a ToxId struct, will query Tox DNS records if necessary
2015-05-18 04:55:50 +08:00
static ToxId resolveToxAddress ( const QString & address , bool silent = true ) ;
2014-11-06 22:12:10 +08:00
2014-11-11 06:55:13 +08:00
static QString queryTox1 ( const QString & record , bool silent = true ) ; ///< Record should look like user@domain.tld. Do *NOT* use tox1 without a good reason, it's unsafe.
static QString queryTox3 ( const tox3_server & server , const QString & record , bool silent = true ) ; ///< Record should look like user@domain.tld, will *NOT* fallback on queryTox1 anymore
2014-11-06 22:12:10 +08:00
protected :
static void showWarning ( const QString & message ) ;
ToxDNS ( ) = default ;
private :
/// Try to fetch the first entry of the given TXT record
/// Returns an empty object on failure. May block for up to ~3s
/// May display message boxes on error if silent if false
static QByteArray fetchLastTextRecord ( const QString & record , bool silent = true ) ;
public :
2015-07-20 07:46:33 +08:00
static const tox3_server pinnedServers [ 3 ] ;
2014-11-06 22:12:10 +08:00
} ;
# endif // QTOXDNS_H