vfs: check userland buffers before reading them.
[haiku.git] / src / add-ons / network_settings / ftpd / FTPServiceAddOn.cpp
blob4476e9ef652968567f6db1be1dc31afe986f7c19
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>
14 #include "ServiceListItem.h"
15 #include "ServiceView.h"
18 using namespace BNetworkKit;
21 #undef B_TRANSLATION_CONTEXT
22 #define B_TRANSLATION_CONTEXT "FTPServiceAddOn"
25 class FTPServiceAddOn : public BNetworkSettingsAddOn {
26 public:
27 FTPServiceAddOn(image_id image,
28 BNetworkSettings& settings);
29 virtual ~FTPServiceAddOn();
31 virtual BNetworkSettingsItem*
32 CreateNextItem(uint32& cookie);
36 class FTPServiceItem : public BNetworkSettingsItem {
37 public:
38 FTPServiceItem(BNetworkSettings& settings);
39 virtual ~FTPServiceItem();
41 virtual BNetworkSettingsType
42 Type() const;
44 virtual BListItem* ListItem();
45 virtual BView* View();
47 virtual status_t Revert();
48 virtual bool IsRevertable();
50 virtual void SettingsUpdated(uint32 which);
52 private:
53 BNetworkSettings& fSettings;
54 BListItem* fItem;
55 ServiceView* fView;
59 // #pragma mark -
62 FTPServiceItem::FTPServiceItem(BNetworkSettings& settings)
64 fSettings(settings),
65 fItem(new ServiceListItem("ftp", B_TRANSLATE("FTP server"), settings)),
66 fView(NULL)
71 FTPServiceItem::~FTPServiceItem()
73 if (fView->Parent() == NULL)
74 delete fView;
76 delete fItem;
80 BNetworkSettingsType
81 FTPServiceItem::Type() const
83 return B_NETWORK_SETTINGS_TYPE_SERVICE;
87 BListItem*
88 FTPServiceItem::ListItem()
90 return fItem;
94 BView*
95 FTPServiceItem::View()
97 if (fView == NULL) {
98 fView = new ServiceView("ftp", "ftpd", B_TRANSLATE("FTP server"),
99 B_TRANSLATE("The FTP server allows you to remotely access the "
100 "files on your machine using the FTP protocol.\n\nPlease note "
101 "that it is an insecure and unencrypted connection."),
102 fSettings);
105 return fView;
109 status_t
110 FTPServiceItem::Revert()
112 return fView != NULL ? fView->Revert() : B_OK;
116 bool
117 FTPServiceItem::IsRevertable()
119 return fView != NULL ? fView->IsRevertable() : false;
123 void
124 FTPServiceItem::SettingsUpdated(uint32 which)
126 if (fView != NULL)
127 fView->SettingsUpdated(which);
131 // #pragma mark -
134 FTPServiceAddOn::FTPServiceAddOn(image_id image,
135 BNetworkSettings& settings)
137 BNetworkSettingsAddOn(image, settings)
142 FTPServiceAddOn::~FTPServiceAddOn()
147 BNetworkSettingsItem*
148 FTPServiceAddOn::CreateNextItem(uint32& cookie)
150 if (cookie++ == 0)
151 return new FTPServiceItem(Settings());
153 return NULL;
157 // #pragma mark -
160 extern "C"
161 BNetworkSettingsAddOn*
162 instantiate_network_settings_add_on(image_id image, BNetworkSettings& settings)
164 return new FTPServiceAddOn(image, settings);