| 1 | /* |
| 2 | Copyright (c) 2007, Trenton Schulz |
| 3 | |
| 4 | Redistribution and use in source and binary forms, with or without |
| 5 | modification, are permitted provided that the following conditions are met: |
| 6 | |
| 7 | 1. Redistributions of source code must retain the above copyright notice, |
| 8 | this list of conditions and the following disclaimer. |
| 9 | |
| 10 | 2. Redistributions in binary form must reproduce the above copyright notice, |
| 11 | this list of conditions and the following disclaimer in the documentation |
| 12 | and/or other materials provided with the distribution. |
| 13 | |
| 14 | 3. The name of the author may not be used to endorse or promote products |
| 15 | derived from this software without specific prior written permission. |
| 16 | |
| 17 | THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED |
| 18 | WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF |
| 19 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO |
| 20 | EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 21 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
| 22 | PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; |
| 23 | OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, |
| 24 | WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR |
| 25 | OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF |
| 26 | ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 27 | */ |
| 28 | |
| 29 | #ifndef BONJOURSERVICERESOLVER_H |
| 30 | #define BONJOURSERVICERESOLVER_H |
| 31 | |
| 32 | #include <QtCore/QObject> |
| 33 | |
| 34 | |
| 35 | #include <dns_sd.h> |
| 36 | |
| 37 | class QSocketNotifier; |
| 38 | class QHostInfo; |
| 39 | class BonjourRecord; |
| 40 | |
| 41 | class BonjourServiceResolver : public QObject |
| 42 | { |
| 43 | Q_OBJECT |
| 44 | public: |
| 45 | BonjourServiceResolver(QObject *parent); |
| 46 | ~BonjourServiceResolver(); |
| 47 | |
| 48 | void resolveBonjourRecord(const BonjourRecord &record); |
| 49 | |
| 50 | signals: |
| 51 | void bonjourRecordResolved(const QHostInfo &hostInfo, int port); |
| 52 | void error(DNSServiceErrorType error); |
| 53 | |
| 54 | private slots: |
| 55 | void bonjourSocketReadyRead(); |
| 56 | void cleanupResolve(); |
| 57 | void finishConnect(const QHostInfo &hostInfo); |
| 58 | |
| 59 | private: |
| 60 | static void DNSSD_API bonjourResolveReply(DNSServiceRef sdRef, DNSServiceFlags flags, |
| 61 | quint32 interfaceIndex, DNSServiceErrorType errorCode, |
| 62 | const char *fullName, const char *hosttarget, quint16 port, |
| 63 | quint16 txtLen, const char *txtRecord, void *context); |
| 64 | DNSServiceRef dnssref; |
| 65 | QSocketNotifier *bonjourSocket; |
| 66 | int bonjourPort; |
| 67 | }; |
| 68 | |
| 69 | #endif // BONJOURSERVICERESOLVER_H |