]> git.ipfire.org Git - thirdparty/pdns.git/blob - pdns/dynlistener.hh
add OpenSSL exception to PowerDNS, Netherlabs, van Dijk and Hubert copyrights
[thirdparty/pdns.git] / pdns / dynlistener.hh
1 /*
2 PowerDNS Versatile Database Driven Nameserver
3 Copyright (C) 2002 - 2008 PowerDNS.COM BV
4
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License version 2
7 as published by the Free Software Foundation
8
9 Additionally, the license of this program contains a special
10 exception which allows to distribute the program in binary form when
11 it is linked against OpenSSL.
12
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21 */
22 #ifndef PDNS_DYNLISTENER
23 #define PDNS_DYNLISTENER
24
25 #include <string>
26 #include <vector>
27 #include <pthread.h>
28 #include <sys/types.h>
29 #include <errno.h>
30 #include <iostream>
31 #include <sstream>
32 #include "iputils.hh"
33 #include <boost/utility.hpp>
34 #include <unistd.h>
35 #include <sys/un.h>
36 #include <dlfcn.h>
37 #include <sys/socket.h>
38 #include <netinet/in.h>
39
40 #include "namespaces.hh"
41
42 class DynListener : public boost::noncopyable
43 {
44 public:
45 explicit DynListener(const string &pname="");
46 explicit DynListener(const ComboAddress& addr);
47 ~DynListener();
48 void go();
49 void theListener();
50 static void *theListenerHelper(void *p);
51
52 typedef string g_funk_t(const vector<string> &parts, Utility::pid_t ppid); // guido!
53 typedef struct { g_funk_t *func; string args; string usage; } g_funkwithusage_t;
54 typedef map<string,g_funkwithusage_t> g_funkdb_t;
55
56 static void registerFunc(const string &name, g_funk_t *gf, const string &usage="", const string &args="");
57 static void registerRestFunc(g_funk_t *gf);
58 static g_funk_t* getFunc(const string& fname) { return s_funcdb[fname].func; }
59 private:
60 void sendlines(const string &lines);
61 string getHelp();
62 string getLine();
63
64 void listenOnUnixDomain(const std::string& fname);
65 void listenOnTCP(const ComboAddress&);
66 void createSocketAndBind(int family, struct sockaddr*local, size_t len);
67
68 Utility::socklen_t d_addrlen;
69 NetmaskGroup d_tcprange;
70 int d_s;
71 int d_client;
72 pthread_t d_tid;
73 bool d_nonlocal;
74 bool d_tcp;
75 pid_t d_ppid;
76
77 string d_socketname;
78 ComboAddress d_socketaddress;
79 static g_funkdb_t s_funcdb;
80 static g_funk_t* s_restfunc;
81 bool testLive(const string& fname);
82 };
83 #endif /* PDNS_DYNLISTENER */