JDNS
qjdns.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2005,2006 Justin Karneges
3  *
4  * Permission is hereby granted, free of charge, to any person obtaining a
5  * copy of this software and associated documentation files (the
6  * "Software"), to deal in the Software without restriction, including
7  * without limitation the rights to use, copy, modify, merge, publish,
8  * distribute, sublicense, and/or sell copies of the Software, and to
9  * permit persons to whom the Software is furnished to do so, subject to
10  * the following conditions:
11  *
12  * The above copyright notice and this permission notice shall be included
13  * in all copies or substantial portions of the Software.
14  *
15  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
16  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
18  * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
19  * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
20  * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
21  * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22  */
23 
30 #ifndef QJDNS_H
31 #define QJDNS_H
32 
33 #include "jdns_export.h"
34 #include <QtCore>
35 #include <QtNetwork>
36 
37 class JDNS_EXPORT QJDns : public QObject
38 {
39  Q_OBJECT
40 public:
41  enum Mode
42  {
43  Unicast,
44  Multicast
45  };
46 
47  enum PublishMode
48  {
49  Unique,
50  Shared
51  };
52 
53  enum Type
54  {
55  A = 1,
56  Aaaa = 28,
57  Mx = 15,
58  Srv = 33,
59  Cname = 5,
60  Ptr = 12,
61  Txt = 16,
62  Hinfo = 13,
63  Ns = 2,
64  Any = 255
65  };
66 
67  enum Error
68  {
69  ErrorGeneric,
72  ErrorConflict
73  };
74 
75  class JDNS_EXPORT NameServer
76  {
77  public:
78  QHostAddress address;
79  int port;
80 
81  NameServer();
82  };
83 
84  class JDNS_EXPORT DnsHost
85  {
86  public:
87  QByteArray name;
88  QHostAddress address;
89  };
90 
91  class JDNS_EXPORT SystemInfo
92  {
93  public:
94  QList<NameServer> nameServers;
95  QList<QByteArray> domains;
96  QList<DnsHost> hosts;
97  };
98 
99  class JDNS_EXPORT Record
100  {
101  public:
102  QByteArray owner;
103  int ttl;
104  int type;
105  QByteArray rdata;
106  bool haveKnown;
107 
108  // known
109  QHostAddress address;
110  QByteArray name;
111  int priority;
112  int weight;
113  int port;
114  QList<QByteArray> texts;
115  QByteArray cpu;
116  QByteArray os;
117 
118  Record();
119  bool verify() const;
120  };
121 
122  class JDNS_EXPORT Response
123  {
124  public:
125  QList<Record> answerRecords;
126  QList<Record> authorityRecords;
127  QList<Record> additionalRecords;
128  };
129 
130  QJDns(QObject *parent = 0);
131  ~QJDns();
132 
133  bool init(Mode mode, const QHostAddress &address);
134  void shutdown();
135  QStringList debugLines();
136 
137  static SystemInfo systemInfo();
138  static QHostAddress detectPrimaryMulticast(const QHostAddress &address);
139 
140  void setNameServers(const QList<NameServer> &list);
141 
142  int queryStart(const QByteArray &name, int type);
143  void queryCancel(int id);
144 
145  // for multicast mode only
146  int publishStart(PublishMode m, const Record &record);
147  void publishUpdate(int id, const Record &record);
148  void publishCancel(int id);
149 
150 signals:
151  void resultsReady(int id, const QJDns::Response &results);
152  void published(int id);
153  void error(int id, QJDns::Error e);
154  void shutdownFinished();
155  void debugLinesReady();
156 
157 private:
158  class Private;
159  friend class Private;
160  Private *d;
161 };
162 
163 #endif
QByteArray name
for Mx, Srv, Cname, Ptr, Ns
Definition: qjdns.h:110
Definition: qjdns.h:122
QHostAddress address
for A, Aaaa
Definition: qjdns.h:109
QByteArray cpu
for Hinfo
Definition: qjdns.h:115
Error
Definition: qjdns.h:67
Preprocessor magic to allow export of library symbols.
Definition: qjdns.h:99
Definition: qjdns.h:84
query only
Definition: qjdns.h:71
QList< QByteArray > texts
for Txt
Definition: qjdns.h:114
Definition: qjdns.h:75
QByteArray os
for Hinfo
Definition: qjdns.h:116
Definition: qjdns.h:91
int weight
for Srv
Definition: qjdns.h:112
int port
for Srv
Definition: qjdns.h:113
int priority
for Mx, Srv
Definition: qjdns.h:111
Definition: qjdns.h:37
query only
Definition: qjdns.h:70