File indexing completed on 2024-04-21 14:55:23

0001 /*  -*- C++ -*-
0002  *  Copyright (C) 2003,2005 Thiago Macieira <thiago@kde.org>
0003  *
0004  *
0005  *  Permission is hereby granted, free of charge, to any person obtaining
0006  *  a copy of this software and associated documentation files (the
0007  *  "Software"), to deal in the Software without restriction, including
0008  *  without limitation the rights to use, copy, modify, merge, publish,
0009  *  distribute, sublicense, and/or sell copies of the Software, and to
0010  *  permit persons to whom the Software is furnished to do so, subject to
0011  *  the following conditions:
0012  *
0013  *  The above copyright notice and this permission notice shall be included
0014  *  in all copies or substantial portions of the Software.
0015  *
0016  *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
0017  *  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
0018  *  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
0019  *  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
0020  *  LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
0021  *  OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
0022  *  WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
0023  */
0024 
0025 #ifndef KRESOLVERSTANDARDWORKERS_P_H
0026 #define KRESOLVERSTANDARDWORKERS_P_H
0027 
0028 #include <sys/types.h>
0029 #include <netdb.h>
0030 
0031 #include <QList>
0032 #include <QByteArray>
0033 #include <QStringList>
0034 
0035 #include "k3resolver.h"
0036 #include "k3resolverworkerbase.h"
0037 
0038 #include <config-network.h>
0039 
0040 namespace KNetwork
0041 {
0042 namespace Internal
0043 {
0044 extern void initStandardWorkers() KDELIBS4SUPPORT_NO_EXPORT;
0045 
0046 /**
0047  * @internal
0048  * The blacklist worker.
0049  */
0050 class KBlacklistWorker: public KNetwork::KResolverWorkerBase
0051 {
0052 public:
0053     static QStringList blacklist;
0054 
0055     static void loadBlacklist();
0056     static void init();
0057     static bool isBlacklisted(const QString &);
0058 
0059     bool preprocess() override;
0060     bool run() override;
0061     bool postprocess() override
0062     {
0063         return true;
0064     }
0065 };
0066 
0067 /** @internal
0068  * Standard worker.
0069  */
0070 class KStandardWorker: public KNetwork::KResolverWorkerBase
0071 {
0072 protected:
0073     mutable QByteArray m_encodedName;
0074     quint16 port;
0075     int scopeid;
0076     QList<KNetwork::KResolverResults *> resultList;
0077 
0078 public:
0079     ~KStandardWorker() override;
0080     bool sanityCheck();
0081 
0082     bool preprocess() override;
0083     bool run() override;
0084     bool postprocess() override;
0085 
0086     bool resolveScopeId();
0087     bool resolveService();
0088     bool resolveNumerically();
0089 
0090     KNetwork::KResolver::ErrorCodes addUnix();
0091 };
0092 
0093 #if HAVE_GETADDRINFO
0094 /** @internal
0095  * Worker class based on getaddrinfo(3).
0096  *
0097  * This class does not do post-processing.
0098  */
0099 class KGetAddrinfoWorker: public KStandardWorker
0100 {
0101 public:
0102     KGetAddrinfoWorker()
0103     { }
0104 
0105     ~KGetAddrinfoWorker() override;
0106     bool preprocess() override;
0107     bool run() override;
0108     bool postprocess() override
0109     {
0110         return true;
0111     }
0112 
0113     bool wantThis(int family);
0114 };
0115 #endif // HAVE_GETADDRINFO
0116 
0117 }
0118 } // namespace KNetwork::Internal
0119 
0120 #endif