[Development] QTBUG-10481: Adding support for DNS SRV lookups

Olivier Goffart olivier at woboq.com
Wed Oct 26 19:44:15 CEST 2011


On Wednesday 26 October 2011 15:15:11 Jeremy Lainé wrote:
> Some time ago a bug [1] was filed against Qt pointing out the fact there
> that Qt4 has no API for doing DNS SRV lookups. Such lookups are important
> for implementing both XMPP and SIP applications, and as such I wrote an
> implementation for the QXmpp [2] project which has been in use for over a
> year. I got some initial feedback from Qt developers both on the merge
> request on gitorious [3] and on IRC, and I adjusted the code accordingly.
> 
> I would like to get some further feedback on the API / implementation in
> order to hopefully get the code merged into Qt, and have submitted it to
> gerrit for review [4]. Comments are welcome!


I'll sumarize my comment on gitorious and what we talked about here:

I think this could be a great addition in QtNetwork (I have not read the code 
itself). 
But I this this is a low level class (in the same sens as QHostInfo is)

What i mean by that is that in practice, developers do not use QHostInfo 
dirrectly, they just want just to write
socket->connect("website.example", "xmpp-server");
And then Qt takes care of internal of looking up the SRV records, so 
application developper do not need to care.

So that API should be IMHO:
QAbstractSocket::connectToHost(QString hostName, QString service, …)
(so you connect to a service name instead of a port number)

Qt would internaly look the srv record of the dns and if they do not exist, 
connect to the default port for that service.
Meaning less code for the application to write

(the way the old KExtandedSocket wokred
http://api.kde.org/3.5-api/kdelibs-
apidocs/kdecore/html/classKExtendedSocket.html#93e3553faaf7dcd4191a3562bc10cc27
or KNetwork::KBufferedSocket
http://api.kde.org/4.x-api/kdelibs-
apidocs/kdecore/html/classKNetwork_1_1KBufferedSocket.html
)


And also, QHostInfo should be
static QHostInfo::lookupHost(QString hostName, QString service, 
                             QObject *receiver, char *slot);
And add a portNumber accessor to QHostInfo

This is also how works the POSIX API (we use) to lookup DNS
int getaddrinfo(const char *node, const char *service,
                const struct addrinfo *hints,
                struct addrinfo **res);
(Notice you should provide a service string, currently Qt do not provide one)



So that class really fits into Qt. But only as a low level class 
(that could even stay internal maybe, I still fail to see a use case for it 
that is not covered by the convinience i suggest)



More information about the Development mailing list