added *basic* ability for services addon to parse xinetd, now we can list active network services in the services view
git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@40317 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -2,6 +2,8 @@
|
||||
* Copyright 2004-2011 Haiku Inc. All rights reserved.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*
|
||||
* Authors:
|
||||
* Alexander von Gluck, [email protected]
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
@@ -12,14 +14,7 @@
|
||||
#include <ScrollView.h>
|
||||
#include <String.h>
|
||||
|
||||
#include "NetworkSetupAddOn.h"
|
||||
|
||||
class ServicesAddOn : public NetworkSetupAddOn {
|
||||
public:
|
||||
ServicesAddOn(image_id addon_image);
|
||||
BView* CreateView(BRect* bounds);
|
||||
const char* Name() { return "Services"; };
|
||||
};
|
||||
#include "ServicesAddOn.h"
|
||||
|
||||
|
||||
NetworkSetupAddOn*
|
||||
@@ -27,10 +22,11 @@ get_nth_addon(image_id image, int index)
|
||||
{
|
||||
if (index != 0)
|
||||
return NULL;
|
||||
|
||||
|
||||
return new ServicesAddOn(image);
|
||||
}
|
||||
|
||||
|
||||
// #pragma mark -
|
||||
ServicesAddOn::ServicesAddOn(image_id image)
|
||||
:
|
||||
@@ -41,24 +37,36 @@ ServicesAddOn::ServicesAddOn(image_id image)
|
||||
|
||||
BView*
|
||||
ServicesAddOn::CreateView(BRect* bounds)
|
||||
{
|
||||
{
|
||||
BRect r = *bounds;
|
||||
if (r.Width() < 100 || r.Height() < 100)
|
||||
r.Set(0, 0, 100, 100);
|
||||
|
||||
|
||||
BRect rlv = r.InsetByCopy(2, 2);
|
||||
rlv.right -= B_V_SCROLL_BAR_WIDTH;
|
||||
BListView* lv = new BListView(rlv, "inetd_services",
|
||||
fServicesListView = new BListView(rlv, "system_services",
|
||||
B_SINGLE_SELECTION_LIST, B_FOLLOW_ALL_SIDES);
|
||||
|
||||
BScrollView* sv = new BScrollView( "inetd_services_scrollview", lv,
|
||||
B_FOLLOW_ALL_SIDES, B_WILL_DRAW | B_FRAME_EVENTS, false, true);
|
||||
|
||||
BScrollView* sv = new BScrollView( "system_services_scrollview",
|
||||
fServicesListView, B_FOLLOW_ALL_SIDES,
|
||||
B_WILL_DRAW | B_FRAME_EVENTS, false, true);
|
||||
|
||||
if (ParseInetd() == B_ERROR)
|
||||
ParseXinetd();
|
||||
|
||||
*bounds = r;
|
||||
return sv;
|
||||
}
|
||||
|
||||
|
||||
status_t
|
||||
ServicesAddOn::ParseInetd()
|
||||
{
|
||||
FILE *f = fopen("/etc/inetd.conf", "r");
|
||||
if (f) {
|
||||
char line[1024], *l;
|
||||
char *token;
|
||||
|
||||
|
||||
while (fgets(line, sizeof(line), f)) {
|
||||
l = line;
|
||||
if (! *l)
|
||||
@@ -72,20 +80,56 @@ ServicesAddOn::CreateView(BRect* bounds)
|
||||
continue;
|
||||
l++; // jump the disable/comment service mark
|
||||
}
|
||||
|
||||
BString label;
|
||||
|
||||
BString label;
|
||||
token = strtok(l, " \t"); // service name
|
||||
label << token;
|
||||
token = strtok(NULL, " \t"); // type
|
||||
label << " (" << token << ")";
|
||||
token = strtok(NULL, " \t"); // protocol
|
||||
label << " " << token;
|
||||
|
||||
lv->AddItem(new BStringItem(label.String()));
|
||||
}
|
||||
fclose(f);
|
||||
}
|
||||
|
||||
*bounds = r;
|
||||
return sv;
|
||||
fServicesListView->AddItem(new BStringItem(label.String()));
|
||||
}
|
||||
fclose(f);
|
||||
return B_OK;
|
||||
} else
|
||||
return B_ERROR;
|
||||
}
|
||||
|
||||
|
||||
status_t
|
||||
ServicesAddOn::ParseXinetd()
|
||||
{
|
||||
FILE *f = fopen("/boot/common/settings/network/services", "r");
|
||||
if (f) {
|
||||
char line[1024], *l;
|
||||
char *token;
|
||||
char *loc;
|
||||
|
||||
while (fgets(line, sizeof(line), f)) {
|
||||
l = line;
|
||||
|
||||
if (! *l)
|
||||
continue;
|
||||
|
||||
if (line[0] == '#' || line[0] == '\n')
|
||||
continue;
|
||||
// Skip commented out lines
|
||||
|
||||
loc = strstr(l, "service ");
|
||||
|
||||
if (loc) {
|
||||
BString label;
|
||||
token = strtok(loc, " ");
|
||||
token = strtok(NULL, " ");
|
||||
label << token;
|
||||
fServicesListView->AddItem(new BStringItem(label.String()));
|
||||
}
|
||||
|
||||
}
|
||||
fclose(f);
|
||||
return B_OK;
|
||||
} else
|
||||
return B_ERROR;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
/*
|
||||
* Copyright 2004-2011 Haiku Inc. All rights reserved.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*
|
||||
* Authors:
|
||||
* Alexander von Gluck, [email protected]
|
||||
*/
|
||||
|
||||
#include "NetworkSetupAddOn.h"
|
||||
|
||||
class ServicesAddOn : public NetworkSetupAddOn {
|
||||
protected:
|
||||
BListView* fServicesListView;
|
||||
public:
|
||||
ServicesAddOn(image_id addon_image);
|
||||
BView* CreateView(BRect* bounds);
|
||||
const char* Name() { return "Services"; };
|
||||
status_t ParseInetd();
|
||||
status_t ParseXinetd();
|
||||
};
|
||||
Reference in New Issue
Block a user