vfs: check userland buffers before reading them.
[haiku.git] / src / add-ons / network_settings / dnsclient / DNSClientServiceAddOn.cpp
blob2cbfec40c5019b2f7e780d83d194169bb3cdd4da
1 /*
2 * Copyright 2015 Haiku, Inc. All rights reserved.
3 * Distributed under the terms of the MIT License.
5 * Authors:
6 * Axel Dörfler, <axeld@pinc-software.de>
7 */
10 #include <Catalog.h>
11 #include <NetworkSettings.h>
12 #include <NetworkSettingsAddOn.h>
13 #include <StringItem.h>
15 #include "DNSSettingsView.h"
18 using namespace BNetworkKit;
21 #undef B_TRANSLATION_CONTEXT
22 #define B_TRANSLATION_CONTEXT "DNSClientServiceAddOn"
25 class DNSClientServiceAddOn : public BNetworkSettingsAddOn {
26 public:
27 DNSClientServiceAddOn(image_id image,
28 BNetworkSettings& settings);
29 virtual ~DNSClientServiceAddOn();
31 virtual BNetworkSettingsItem*
32 CreateNextItem(uint32& cookie);
36 class DNSClientServiceItem : public BNetworkSettingsItem {
37 public:
38 DNSClientServiceItem(
39 BNetworkSettings& settings);
40 virtual ~DNSClientServiceItem();
42 virtual BNetworkSettingsType
43 Type() const;
45 virtual BListItem* ListItem();
46 virtual BView* View();
48 virtual status_t Revert();
49 virtual bool IsRevertable();
51 private:
52 BNetworkSettings& fSettings;
53 BStringItem* fItem;
54 DNSSettingsView* fView;
58 // #pragma mark -
61 DNSClientServiceItem::DNSClientServiceItem(BNetworkSettings& settings)
63 fSettings(settings),
64 fItem(new BStringItem(B_TRANSLATE("DNS settings"))),
65 fView(NULL)
70 DNSClientServiceItem::~DNSClientServiceItem()
72 if (fView->Parent() == NULL)
73 delete fView;
75 delete fItem;
79 BNetworkSettingsType
80 DNSClientServiceItem::Type() const
82 return B_NETWORK_SETTINGS_TYPE_SERVICE;
86 BListItem*
87 DNSClientServiceItem::ListItem()
89 return fItem;
93 BView*
94 DNSClientServiceItem::View()
96 if (fView == NULL)
97 fView = new DNSSettingsView(this);
99 return fView;
103 status_t
104 DNSClientServiceItem::Revert()
106 return B_OK;
110 bool
111 DNSClientServiceItem::IsRevertable()
113 return false;
117 // #pragma mark -
120 DNSClientServiceAddOn::DNSClientServiceAddOn(image_id image,
121 BNetworkSettings& settings)
123 BNetworkSettingsAddOn(image, settings)
128 DNSClientServiceAddOn::~DNSClientServiceAddOn()
133 BNetworkSettingsItem*
134 DNSClientServiceAddOn::CreateNextItem(uint32& cookie)
136 if (cookie++ == 0)
137 return new DNSClientServiceItem(Settings());
139 return NULL;
143 // #pragma mark -
146 extern "C"
147 BNetworkSettingsAddOn*
148 instantiate_network_settings_add_on(image_id image, BNetworkSettings& settings)
150 return new DNSClientServiceAddOn(image, settings);