1 | /* $Id: HostDnsService.h 49228 2013-10-22 12:24:28Z 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 |
|
---|
27 | #include <list>
|
---|
28 |
|
---|
29 | typedef std::list<com::Utf8Str> Utf8StrList;
|
---|
30 | typedef Utf8StrList::iterator Utf8StrListIterator;
|
---|
31 |
|
---|
32 |
|
---|
33 | class Lockee
|
---|
34 | {
|
---|
35 | public:
|
---|
36 | Lockee();
|
---|
37 | virtual ~Lockee();
|
---|
38 | const RTCRITSECT* lock() const;
|
---|
39 |
|
---|
40 | private:
|
---|
41 | RTCRITSECT mLock;
|
---|
42 | };
|
---|
43 |
|
---|
44 |
|
---|
45 | class ALock
|
---|
46 | {
|
---|
47 | public:
|
---|
48 | ALock(const Lockee *l);
|
---|
49 | ~ALock();
|
---|
50 |
|
---|
51 | private:
|
---|
52 | const Lockee *lck;
|
---|
53 | };
|
---|
54 |
|
---|
55 |
|
---|
56 | class HostDnsService
|
---|
57 | {
|
---|
58 | public:
|
---|
59 | HostDnsService();
|
---|
60 | virtual ~HostDnsService();
|
---|
61 | virtual HRESULT init(const VirtualBox *aParent);
|
---|
62 | virtual HRESULT start(void);
|
---|
63 | virtual void stop(void);
|
---|
64 | STDMETHOD(COMGETTER(NameServers))(ComSafeArrayOut(BSTR, aNameServers));
|
---|
65 | STDMETHOD(COMGETTER(DomainName))(BSTR *aDomainName);
|
---|
66 | STDMETHOD(COMGETTER(SearchStrings))(ComSafeArrayOut(BSTR, aSearchStrings));
|
---|
67 |
|
---|
68 | protected:
|
---|
69 | virtual HRESULT update(void);
|
---|
70 |
|
---|
71 | /* XXX: hide it with struct Data together with <list> */
|
---|
72 | Utf8StrList m_llNameServers;
|
---|
73 | Utf8StrList m_llSearchStrings;
|
---|
74 | com::Utf8Str m_DomainName;
|
---|
75 | RTCRITSECT m_hCritSect;
|
---|
76 |
|
---|
77 | private:
|
---|
78 | const VirtualBox *mParent;
|
---|
79 | HostDnsService(const HostDnsService&);
|
---|
80 | HostDnsService& operator =(const HostDnsService&);
|
---|
81 | };
|
---|
82 |
|
---|
83 | # ifdef RT_OS_DARWIN
|
---|
84 | class HostDnsServiceDarwin: public HostDnsService
|
---|
85 | {
|
---|
86 | public:
|
---|
87 | HostDnsServiceDarwin();
|
---|
88 | virtual ~HostDnsServiceDarwin();
|
---|
89 |
|
---|
90 | virtual HRESULT init(const VirtualBox *aParent);
|
---|
91 | virtual HRESULT start(void);
|
---|
92 | virtual void stop(void);
|
---|
93 | virtual HRESULT update();
|
---|
94 |
|
---|
95 | private:
|
---|
96 | static void hostDnsServiceStoreCallback(void *store, void *arrayRef, void *info);
|
---|
97 |
|
---|
98 | };
|
---|
99 | # endif
|
---|
100 |
|
---|
101 | # ifdef RT_OS_WINDOWS
|
---|
102 | class HostDnsServiceWin: public HostDnsService
|
---|
103 | {
|
---|
104 | public:
|
---|
105 | HostDnsServiceWin();
|
---|
106 | virtual ~HostDnsServiceWin();
|
---|
107 |
|
---|
108 | virtual HRESULT init(const VirtualBox *aParent);
|
---|
109 | virtual HRESULT start(void);
|
---|
110 | virtual void stop(void);
|
---|
111 | virtual HRESULT update();
|
---|
112 | void strList2List(Utf8StrList& lst, char *strLst);
|
---|
113 | };
|
---|
114 | # endif
|
---|
115 |
|
---|
116 | #if defined(RT_OS_SOLARIS) || defined(RT_OS_LINUX) || defined(RT_OS_OS2)
|
---|
117 |
|
---|
118 | class HostDnsServiceResolvConf: public HostDnsService
|
---|
119 | {
|
---|
120 | public:
|
---|
121 | HostDnsServiceResolvConf(const char *aResolvConfFileName = "/etc/resolv.conf");
|
---|
122 | virtual ~HostDnsServiceResolvConf();
|
---|
123 | virtual HRESULT init(const VirtualBox *aParent);
|
---|
124 | virtual HRESULT update();
|
---|
125 | const com::Utf8Str resolvConf() {return m_ResolvConfFilename; }
|
---|
126 | protected:
|
---|
127 | com::Utf8Str m_ResolvConfFilename;
|
---|
128 | RTFILE m_ResolvConfFile;
|
---|
129 | };
|
---|
130 |
|
---|
131 | # if defined(RT_OS_SOLARIS)
|
---|
132 | /**
|
---|
133 | * XXX: https://blogs.oracle.com/praks/entry/file_events_notification
|
---|
134 | */
|
---|
135 | class HostDnsServiceSolaris: public HostDnsServiceResolvConf
|
---|
136 | {
|
---|
137 | public:
|
---|
138 | HostDnsServiceSolaris(){}
|
---|
139 | virtual ~HostDnsServiceSolaris(){}
|
---|
140 | };
|
---|
141 | # elif defined(RT_OS_LINUX)
|
---|
142 | class HostDnsServiceLinux: public HostDnsServiceResolvConf
|
---|
143 | {
|
---|
144 | public:
|
---|
145 | HostDnsServiceLinux(){}
|
---|
146 | virtual ~HostDnsServiceLinux(){}
|
---|
147 | virtual HRESULT init(const VirtualBox *aParent);
|
---|
148 | virtual void stop(void);
|
---|
149 |
|
---|
150 | static int hostMonitoringRoutine(RTTHREAD ThreadSelf, void *pvUser);
|
---|
151 | };
|
---|
152 |
|
---|
153 | # elif defined(RT_OS_OS2)
|
---|
154 | class HostDnsServiceOs2: public HostDnsServiceResolvConf
|
---|
155 | {
|
---|
156 | public:
|
---|
157 | HostDnsServiceOs2()
|
---|
158 | {
|
---|
159 | /* XXX: \\MPTN\\ETC should be taken from environment variable ETC */
|
---|
160 | ::HostDnsServiceResolvConf("\\MPTN\\ETC\\RESOLV2");
|
---|
161 | }
|
---|
162 | virtual ~HostDnsServiceOs2(){}
|
---|
163 | };
|
---|
164 | # endif
|
---|
165 | #endif
|
---|
166 |
|
---|
167 | #endif /* !___H_DNSHOSTSERVICE */
|
---|