VirtualBox

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

Last change on this file since 55198 was 55198, checked in by vboxsync, 10 years ago

Main/HostDnsService: drop const from VirtualBox *aParent as
GetExtraData() method is not const.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 5.8 KB
Line 
1/* $Id: HostDnsService.h 55198 2015-04-13 01:59:07Z vboxsync $ */
2/** @file
3 * Host DNS listener.
4 */
5
6/*
7 * Copyright (C) 2005-2012 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 ___H_DNSHOSTSERVICE
19#define ___H_DNSHOSTSERVICE
20#include "VirtualBoxBase.h"
21
22#include <iprt/cdefs.h>
23#include <iprt/critsect.h>
24#include <iprt/types.h>
25
26#include <list>
27#include <vector>
28
29typedef std::list<com::Utf8Str> Utf8StrList;
30typedef Utf8StrList::iterator Utf8StrListIterator;
31
32class HostDnsMonitorProxy;
33typedef const HostDnsMonitorProxy *PCHostDnsMonitorProxy;
34
35class Lockee
36{
37 public:
38 Lockee();
39 virtual ~Lockee();
40 const RTCRITSECT* lock() const;
41
42 private:
43 RTCRITSECT mLock;
44};
45
46class ALock
47{
48 public:
49 explicit ALock(const Lockee *l);
50 ~ALock();
51
52 private:
53 const Lockee *lockee;
54};
55
56class HostDnsInformation
57{
58 public:
59 std::vector<std::string> servers;
60 std::string domain;
61 std::vector<std::string> searchList;
62 bool equals(const HostDnsInformation &) const;
63};
64
65/**
66 * This class supposed to be a real DNS monitor object it should be singleton,
67 * it lifecycle starts and ends together with VBoxSVC.
68 */
69class HostDnsMonitor : public Lockee
70{
71 public:
72 static const HostDnsMonitor *getHostDnsMonitor();
73 static void shutdown();
74
75 void addMonitorProxy(PCHostDnsMonitorProxy) const;
76 void releaseMonitorProxy(PCHostDnsMonitorProxy) const;
77 const HostDnsInformation &getInfo() const;
78 /* @note: method will wait till client call
79 HostDnsService::monitorThreadInitializationDone() */
80 virtual HRESULT init();
81
82 protected:
83 explicit HostDnsMonitor(bool fThreaded = false);
84 virtual ~HostDnsMonitor();
85
86 void setInfo(const HostDnsInformation &);
87
88 /* this function used only if HostDnsMonitor::HostDnsMonitor(true) */
89 void monitorThreadInitializationDone();
90 virtual void monitorThreadShutdown() = 0;
91 virtual int monitorWorker() = 0;
92
93 private:
94 HostDnsMonitor(const HostDnsMonitor &);
95 HostDnsMonitor& operator= (const HostDnsMonitor &);
96 static int threadMonitoringRoutine(RTTHREAD, void *);
97
98 public:
99 struct Data;
100 Data *m;
101};
102
103/**
104 * This class supposed to be a proxy for events on changing Host Name Resolving configurations.
105 */
106class HostDnsMonitorProxy : public Lockee
107{
108 public:
109 HostDnsMonitorProxy();
110 ~HostDnsMonitorProxy();
111 void init(const HostDnsMonitor *aMonitor, VirtualBox *aParent);
112 void notify() const;
113
114 HRESULT GetNameServers(std::vector<com::Utf8Str> &aNameServers);
115 HRESULT GetDomainName(com::Utf8Str *pDomainName);
116 HRESULT GetSearchStrings(std::vector<com::Utf8Str> &aSearchStrings);
117
118 bool operator==(PCHostDnsMonitorProxy&);
119
120 private:
121 void updateInfo();
122
123 private:
124 struct Data;
125 Data *m;
126};
127
128# ifdef RT_OS_DARWIN
129class HostDnsServiceDarwin : public HostDnsMonitor
130{
131 public:
132 HostDnsServiceDarwin();
133 ~HostDnsServiceDarwin();
134 HRESULT init();
135
136 protected:
137 virtual void monitorThreadShutdown();
138 virtual int monitorWorker();
139
140 private:
141 HRESULT updateInfo();
142 static void hostDnsServiceStoreCallback(void *store, void *arrayRef, void *info);
143 struct Data;
144 Data *m;
145};
146# endif
147# ifdef RT_OS_WINDOWS
148class HostDnsServiceWin : public HostDnsMonitor
149{
150 public:
151 HostDnsServiceWin();
152 ~HostDnsServiceWin();
153 HRESULT init();
154
155 protected:
156 virtual void monitorThreadShutdown();
157 virtual int monitorWorker();
158
159 private:
160 HRESULT updateInfo();
161
162 private:
163 struct Data;
164 Data *m;
165};
166# endif
167# if defined(RT_OS_SOLARIS) || defined(RT_OS_LINUX) || defined(RT_OS_OS2) || defined(RT_OS_FREEBSD)
168class HostDnsServiceResolvConf: public HostDnsMonitor
169{
170 public:
171 explicit HostDnsServiceResolvConf(bool fThreaded = false) : HostDnsMonitor(fThreaded), m(NULL) {}
172 virtual ~HostDnsServiceResolvConf();
173 virtual HRESULT init(const char *aResolvConfFileName);
174 const std::string& resolvConf() const;
175
176 protected:
177 HRESULT readResolvConf();
178 /* While not all hosts supports Hosts DNS change notifiaction
179 * default implementation offers return VERR_IGNORE.
180 */
181 virtual void monitorThreadShutdown() {}
182 virtual int monitorWorker() {return VERR_IGNORED;}
183
184 protected:
185 struct Data;
186 Data *m;
187};
188# if defined(RT_OS_SOLARIS)
189/**
190 * XXX: https://blogs.oracle.com/praks/entry/file_events_notification
191 */
192class HostDnsServiceSolaris : public HostDnsServiceResolvConf
193{
194 public:
195 HostDnsServiceSolaris(){}
196 ~HostDnsServiceSolaris(){}
197 HRESULT init(){ return HostDnsServiceResolvConf::init("/etc/resolv.conf");}
198};
199
200# elif defined(RT_OS_LINUX)
201class HostDnsServiceLinux : public HostDnsServiceResolvConf
202{
203 public:
204 HostDnsServiceLinux():HostDnsServiceResolvConf(true){}
205 virtual ~HostDnsServiceLinux();
206 virtual HRESULT init(){ return HostDnsServiceResolvConf::init("/etc/resolv.conf");}
207
208 protected:
209 virtual void monitorThreadShutdown();
210 virtual int monitorWorker();
211};
212
213# elif defined(RT_OS_FREEBSD)
214class HostDnsServiceFreebsd: public HostDnsServiceResolvConf
215{
216 public:
217 HostDnsServiceFreebsd(){}
218 ~HostDnsServiceFreebsd(){}
219 HRESULT init(){ return HostDnsServiceResolvConf::init("/etc/resolv.conf");}
220};
221
222# elif defined(RT_OS_OS2)
223class HostDnsServiceOs2 : public HostDnsServiceResolvConf
224{
225 public:
226 HostDnsServiceOs2(){}
227 ~HostDnsServiceOs2(){}
228 /* XXX: \\MPTN\\ETC should be taken from environment variable ETC */
229 HRESULT init(){ return init("\\MPTN\\ETC\\RESOLV2");}
230};
231
232# endif
233# endif
234
235#endif /* !___H_DNSHOSTSERVICE */
Note: See TracBrowser for help on using the repository browser.

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