netnames.h

00001 /*
00002  * Copyright (C) 2006  Justin Karneges
00003  *
00004  * This library is free software; you can redistribute it and/or
00005  * modify it under the terms of the GNU Lesser General Public
00006  * License as published by the Free Software Foundation; either
00007  * version 2.1 of the License, or (at your option) any later version.
00008  *
00009  * This library is distributed in the hope that it will be useful,
00010  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012  * Lesser General Public License for more details.
00013  *
00014  * You should have received a copy of the GNU Lesser General Public
00015  * License along with this library; if not, write to the Free Software
00016  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
00017  * 02110-1301  USA
00018  *
00019  */
00020 
00021 #ifndef NETNAMES_H
00022 #define NETNAMES_H
00023 
00024 #include <QtCore>
00025 #include <QtNetwork>
00026 #include "irisnetglobal.h"
00027 
00028 namespace XMPP {
00029 
00030 class NameManager;
00031 
00032 class IRISNET_EXPORT NetNames
00033 {
00034 public:
00035         // free any shared data, shutdown internal dns sessions if necessary.
00036         static void cleanup();
00037 
00038         // return current diagnostic text, clear the buffer.
00039         static QString diagnosticText();
00040 
00041         // convert idn names
00042         static QByteArray idnaFromString(const QString &in);
00043         static QString idnaToString(const QByteArray &in);
00044 
00045         // dns escaping
00046         static QByteArray escapeDomain(const QByteArray &in);
00047         static QByteArray unescapeDomain(const QByteArray &in);
00048 
00049 private:
00050         NetNames();
00051 };
00052 
00083 class IRISNET_EXPORT NameRecord
00084 {
00085 public:
00091         enum Type
00092         {
00093                 A,     
00094                 Aaaa,  
00095                 Mx,    
00096                 Srv,   
00097                 Cname, 
00098                 Ptr,   
00099                 Txt,   
00100                 Hinfo, 
00101                 Ns,    
00102                 Null,  
00103                 Any    
00104         };
00105 
00111         NameRecord();
00112 
00118         NameRecord(const QByteArray &owner, int ttl);
00119 
00123         NameRecord(const NameRecord &from);
00124 
00128         ~NameRecord();
00129 
00133         NameRecord & operator=(const NameRecord &from);
00134 
00140         bool isNull() const; // don't confuse with Null type
00141 
00149         QByteArray owner() const;
00150 
00160         int ttl() const;
00161 
00165         Type type() const;
00166 
00172         QHostAddress address() const;
00173 
00179         QByteArray name() const;
00180 
00186         int priority() const;
00187 
00193         int weight() const;
00194 
00200         int port() const;
00201 
00207         QList<QByteArray> texts() const;
00208 
00214         QByteArray cpu() const;
00215 
00221         QByteArray os() const;
00222 
00228         QByteArray rawData() const;
00229 
00235         void setOwner(const QByteArray &name);
00236 
00242         void setTTL(int seconds);
00243 
00249         void setAddress(const QHostAddress &a);
00250 
00254         void setMx(const QByteArray &name, int priority);
00255 
00259         void setSrv(const QByteArray &name, int port, int priority, int weight);
00260 
00264         void setCname(const QByteArray &name);
00265 
00269         void setPtr(const QByteArray &name);
00270 
00274         void setTxt(const QList<QByteArray> &texts);
00275 
00279         void setHinfo(const QByteArray &cpu, const QByteArray &os);
00280 
00284         void setNs(const QByteArray &name);
00285 
00289         void setNull(const QByteArray &rawData);
00290 
00291 private:
00292         class Private;
00293         QSharedDataPointer<Private> d;
00294 };
00295 
00296 class IRISNET_EXPORT ServiceInstance
00297 {
00298 public:
00299         ServiceInstance();
00300         ServiceInstance(const QString &instance, const QString &type, const QString &domain, const QMap<QString,QByteArray> &attributes);
00301         ServiceInstance(const ServiceInstance &from);
00302         ~ServiceInstance();
00303         ServiceInstance & operator=(const ServiceInstance &from);
00304 
00305         QString instance() const;
00306         QString type() const;
00307         QString domain() const;
00308         QMap<QString,QByteArray> attributes() const;
00309         QByteArray name() const; // full dns label
00310 
00311 private:
00312         class Private;
00313         QSharedDataPointer<Private> d;
00314 
00315         friend class NameManager;
00316 };
00317 
00375 class IRISNET_EXPORT NameResolver : public QObject
00376 {
00377         Q_OBJECT
00378 public:
00382         enum Mode
00383         {
00384                 Single,       
00385                 LongLived     
00386         };
00387 
00391         enum Error
00392         {
00393                 ErrorGeneric,     
00394                 ErrorNoName,      
00395                 ErrorTimeout,     
00396                 ErrorNoLocal,     
00397                 ErrorNoLongLived  
00398         };
00399 
00403         NameResolver(QObject *parent = 0);
00404 
00410         ~NameResolver();
00411 
00419         void start(const QByteArray &name, NameRecord::Type type = NameRecord::A, Mode mode = Single);
00420 
00428         void stop();
00429 
00430 signals:
00438         void resultsReady(const QList<XMPP::NameRecord> &results);
00439 
00445         void error(XMPP::NameResolver::Error e);
00446 
00447 private:
00448         class Private;
00449         friend class Private;
00450         Private *d;
00451 
00452         friend class NameManager;
00453 };
00454 
00455 class IRISNET_EXPORT ServiceBrowser : public QObject
00456 {
00457         Q_OBJECT
00458 public:
00459         ServiceBrowser(QObject *parent = 0);
00460         ~ServiceBrowser();
00461 
00462         void start(const QString &type, const QString &domain = "local");
00463         void stop();
00464 
00465 signals:
00466         void instanceAvailable(const XMPP::ServiceInstance &instance);
00467         void instanceUnavailable(const XMPP::ServiceInstance &instance);
00468         void error();
00469 
00470 private:
00471         class Private;
00472         friend class Private;
00473         Private *d;
00474 
00475         friend class NameManager;
00476 };
00477 
00478 class IRISNET_EXPORT ServiceResolver : public QObject
00479 {
00480         Q_OBJECT
00481 public:
00482         ServiceResolver(QObject *parent = 0);
00483         ~ServiceResolver();
00484 
00485         void startFromInstance(const QByteArray &name);
00486         void startFromDomain(const QString &domain, const QString &type);
00487         void startFromPlain(const QString &host, int port); // non-SRV
00488         void tryNext();
00489         void stop();
00490 
00491 signals:
00492         void resultsReady(const QHostAddress &address, int port);
00493         void finished();
00494         void error(); // SRV lookup failed
00495 
00496 private:
00497         class Private;
00498         friend class Private;
00499         Private *d;
00500 
00501         friend class NameManager;
00502 };
00503 
00504 class IRISNET_EXPORT ServiceLocalPublisher : public QObject
00505 {
00506         Q_OBJECT
00507 public:
00508         enum Error
00509         {
00510                 ErrorGeneric,  // generic error
00511                 ErrorConflict, // name in use
00512                 ErrorNoLocal   // unable to setup multicast dns
00513         };
00514 
00515         ServiceLocalPublisher(QObject *parent = 0);
00516         ~ServiceLocalPublisher();
00517 
00518         void publish(const QString &instance, const QString &type, int port, const QMap<QString,QByteArray> &attributes);
00519         void updateAttributes(const QMap<QString,QByteArray> &attributes);
00520         void addRecord(const NameRecord &rec);
00521         void cancel();
00522 
00523 signals:
00524         void published();
00525         void error(XMPP::ServiceLocalPublisher::Error e);
00526 
00527 private:
00528         class Private;
00529         friend class Private;
00530         Private *d;
00531 
00532         friend class NameManager;
00533 };
00534 
00535 }
00536 
00537 #endif

Generated on Sun Mar 18 17:58:50 2007 for IrisNet by  doxygen 1.4.6