VirtualBox

source: vbox/trunk/src/VBox/Main/src-server/HostDnsService.h@ 77985

Last change on this file since 77985 was 77985, checked in by vboxsync, 6 years ago

Main/HostDnsService: Renaming and cleanup (no functional changes) [build fix].

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 6.5 KB
Line 
1/* $Id: HostDnsService.h 77985 2019-04-02 14:12:23Z vboxsync $ */
2/** @file
3 * Host DNS listener.
4 */
5
6/*
7 * Copyright (C) 2005-2019 Oracle Corporation
8 *
9 * This file is part of VirtualBox Open Source Edition (OSE), as
10 * available from http://www.virtualbox.org. This file is free software;
11 * you can redistribute it and/or modify it under the terms of the GNU
12 * General Public License (GPL) as published by the Free Software
13 * Foundation, in version 2 as it comes in the "COPYING" file of the
14 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
15 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
16 */
17
18#ifndef MAIN_INCLUDED_SRC_src_server_HostDnsService_h
19#define MAIN_INCLUDED_SRC_src_server_HostDnsService_h
20#ifndef RT_WITHOUT_PRAGMA_ONCE
21# pragma once
22#endif
23#include "VirtualBoxBase.h"
24
25#include <iprt/err.h> /* VERR_IGNORED */
26#include <iprt/cpp/lock.h>
27
28#include <list>
29#include <vector>
30
31typedef std::list<com::Utf8Str> Utf8StrList;
32typedef Utf8StrList::iterator Utf8StrListIterator;
33
34class HostDnsMonitorProxy;
35typedef const HostDnsMonitorProxy *PCHostDnsMonitorProxy;
36
37class HostDnsInformation
38{
39 public:
40 static const uint32_t IGNORE_SERVER_ORDER = RT_BIT_32(0);
41 static const uint32_t IGNORE_SUFFIXES = RT_BIT_32(1);
42
43 public:
44 std::vector<std::string> servers;
45 std::string domain;
46 std::vector<std::string> searchList;
47 bool equals(const HostDnsInformation &, uint32_t fLaxComparison = 0) const;
48};
49
50/**
51 * This class supposed to be a real DNS monitor object it should be singleton,
52 * it lifecycle starts and ends together with VBoxSVC.
53 */
54class HostDnsServiceBase
55{
56 DECLARE_CLS_COPY_CTOR_ASSIGN_NOOP(HostDnsServiceBase);
57
58public:
59
60 static HostDnsServiceBase *createHostDnsMonitor(void);
61 void shutdown();
62
63 /* @note: method will wait till client call
64 HostDnsService::monitorThreadInitializationDone() */
65 virtual HRESULT init(HostDnsMonitorProxy *pProxy);
66
67protected:
68
69 explicit HostDnsServiceBase(bool fThreaded = false);
70 virtual ~HostDnsServiceBase();
71
72 void setInfo(const HostDnsInformation &);
73
74 /* this function used only if HostDnsMonitor::HostDnsMonitor(true) */
75 void monitorThreadInitializationDone();
76 virtual void monitorThreadShutdown() = 0;
77 virtual int monitorWorker() = 0;
78
79private:
80
81 static DECLCALLBACK(int) threadMonitoringRoutine(RTTHREAD, void *);
82
83protected:
84
85 mutable RTCLockMtx m_LockMtx;
86
87public: /** @todo r=andy Why is this public? */
88
89 struct Data;
90 Data *m;
91};
92
93/**
94 * This class supposed to be a proxy for events on changing Host Name Resolving configurations.
95 */
96class HostDnsMonitorProxy
97{
98public:
99
100 HostDnsMonitorProxy();
101 virtual ~HostDnsMonitorProxy();
102
103public:
104
105 void init(VirtualBox *virtualbox);
106 void uninit();
107 void notify(const HostDnsInformation &info);
108
109 HRESULT GetNameServers(std::vector<com::Utf8Str> &aNameServers);
110 HRESULT GetDomainName(com::Utf8Str *pDomainName);
111 HRESULT GetSearchStrings(std::vector<com::Utf8Str> &aSearchStrings);
112
113private:
114
115 void pollGlobalExtraData();
116 bool updateInfo(const HostDnsInformation &info);
117
118private:
119
120 mutable RTCLockMtx m_LockMtx;
121
122 struct Data;
123 Data *m;
124};
125
126# if defined(RT_OS_DARWIN) || defined(DOXYGEN_RUNNING)
127class HostDnsServiceDarwin : public HostDnsServiceBase
128{
129public:
130 HostDnsServiceDarwin();
131 virtual ~HostDnsServiceDarwin();
132
133public:
134
135 virtual HRESULT init(HostDnsMonitorProxy *pProxy);
136
137protected:
138
139 virtual void monitorThreadShutdown();
140 virtual int monitorWorker();
141
142private:
143
144 HRESULT updateInfo();
145 static void hostDnsServiceStoreCallback(void *store, void *arrayRef, void *info);
146 struct Data;
147 Data *m;
148};
149# endif
150# if defined(RT_OS_WINDOWS) || defined(DOXYGEN_RUNNING)
151class HostDnsServiceWin : public HostDnsServiceBase
152{
153public:
154 HostDnsServiceWin();
155 virtual ~HostDnsServiceWin();
156
157public:
158
159 virtual HRESULT init(HostDnsMonitorProxy *pProxy);
160
161protected:
162
163 virtual void monitorThreadShutdown();
164 virtual int monitorWorker();
165
166private:
167
168 HRESULT updateInfo();
169
170 private:
171 struct Data;
172 Data *m;
173};
174# endif
175# if defined(RT_OS_SOLARIS) || defined(RT_OS_LINUX) || defined(RT_OS_OS2) || defined(RT_OS_FREEBSD) \
176 || defined(DOXYGEN_RUNNING)
177class HostDnsServiceResolvConf: public HostDnsServiceBase
178{
179public:
180
181 explicit HostDnsServiceResolvConf(bool fThreaded = false) : HostDnsServiceBase(fThreaded), m(NULL) {}
182 virtual ~HostDnsServiceResolvConf();
183
184public:
185
186 virtual HRESULT init(HostDnsMonitorProxy *pProxy, const char *aResolvConfFileName);
187 const std::string& resolvConf() const;
188
189protected:
190
191 HRESULT readResolvConf();
192 /* While not all hosts supports Hosts DNS change notifiaction
193 * default implementation offers return VERR_IGNORE.
194 */
195 virtual void monitorThreadShutdown() {}
196 virtual int monitorWorker() {return VERR_IGNORED;}
197
198protected:
199
200 struct Data;
201 Data *m;
202};
203# if defined(RT_OS_SOLARIS) || defined(DOXYGEN_RUNNING)
204/**
205 * XXX: https://blogs.oracle.com/praks/entry/file_events_notification
206 */
207class HostDnsServiceSolaris : public HostDnsServiceResolvConf
208{
209public:
210
211 HostDnsServiceSolaris(){}
212 virtual ~HostDnsServiceSolaris(){}
213
214public:
215
216 virtual HRESULT init(HostDnsMonitorProxy *pProxy) {
217 return HostDnsServiceResolvConf::init(pProxy, "/etc/resolv.conf");
218 }
219};
220
221# endif
222# if defined(RT_OS_LINUX) || defined(DOXYGEN_RUNNING)
223class HostDnsServiceLinux : public HostDnsServiceResolvConf
224{
225public:
226
227 HostDnsServiceLinux() : HostDnsServiceResolvConf(true) {}
228 virtual ~HostDnsServiceLinux();
229
230public:
231
232 virtual HRESULT init(HostDnsMonitorProxy *pProxy) {
233 return HostDnsServiceResolvConf::init(pProxy, "/etc/resolv.conf");
234 }
235
236protected:
237
238 virtual void monitorThreadShutdown();
239 virtual int monitorWorker();
240};
241
242# endif
243# if defined(RT_OS_FREEBSD) || defined(DOXYGEN_RUNNING)
244class HostDnsServiceFreebsd: public HostDnsServiceResolvConf
245{
246public:
247
248 HostDnsServiceFreebsd(){}
249 virtual ~HostDnsServiceFreebsd() {}
250
251public:
252
253 virtual HRESULT init(HostDnsMonitorProxy *pProxy) {
254 return HostDnsServiceResolvConf::init(pProxy, "/etc/resolv.conf");
255 }
256};
257
258# endif
259# if defined(RT_OS_OS2) || defined(DOXYGEN_RUNNING)
260class HostDnsServiceOs2 : public HostDnsServiceResolvConf
261{
262public:
263
264 HostDnsServiceOs2() {}
265 virtual ~HostDnsServiceOs2() {}
266
267public:
268
269 /* XXX: \\MPTN\\ETC should be taken from environment variable ETC */
270 virtual HRESULT init(HostDnsMonitorProxy *pProxy) {
271 return HostDnsServiceResolvConf::init(pProxy, "\\MPTN\\ETC\\RESOLV2");
272 }
273};
274
275# endif
276# endif
277
278#endif /* !MAIN_INCLUDED_SRC_src_server_HostDnsService_h */
Note: See TracBrowser for help on using the repository browser.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette