Style cleanup, patch by Vasilis Kaoutsis - thanks!

git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@20430 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Axel Dörfler
2007-03-27 00:14:30 +00:00
parent a71744ba3a
commit fc1cf1a3d2
21 changed files with 872 additions and 853 deletions
@@ -1,5 +1,5 @@
/*
* Copyright 2003-2004, Waldemar Kornewald <[email protected]>
* Copyright 2003-2007, Waldemar Kornewald <[email protected]>
* Distributed under the terms of the MIT License.
*/
@@ -33,21 +33,21 @@ KPPPConfigurePacket::KPPPConfigurePacket(struct mbuf *packet)
ppp_lcp_packet *header = mtod(packet, ppp_lcp_packet*);
SetID(header->id);
if(!SetCode(header->code))
if (!SetCode(header->code))
return;
uint16 length = ntohs(header->length);
if(length < 6 || length > packet->m_len)
if (length < 6 || length > packet->m_len)
return;
// there are no items (or one corrupted item)
int32 position = 0;
ppp_configure_item *item;
while(position < length - 4) {
while (position < length - 4) {
item = (ppp_configure_item*) (header->data + position);
if(item->length < 2)
if (item->length < 2)
return;
// found a corrupted item
@@ -60,7 +60,7 @@ KPPPConfigurePacket::KPPPConfigurePacket(struct mbuf *packet)
//! Frees all items.
KPPPConfigurePacket::~KPPPConfigurePacket()
{
for(int32 index = 0; index < CountItems(); index++)
for (int32 index = 0; index < CountItems(); index++)
free(ItemAt(index));
}
@@ -70,7 +70,7 @@ bool
KPPPConfigurePacket::SetCode(uint8 code)
{
// only configure codes are allowed!
if(code < PPP_CONFIGURE_REQUEST || code > PPP_CONFIGURE_REJECT)
if (code < PPP_CONFIGURE_REQUEST || code > PPP_CONFIGURE_REJECT)
return false;
fCode = code;
@@ -94,18 +94,18 @@ KPPPConfigurePacket::SetCode(uint8 code)
bool
KPPPConfigurePacket::AddItem(const ppp_configure_item *item, int32 index)
{
if(!item || item->length < 2)
if (!item || item->length < 2)
return false;
ppp_configure_item *add = (ppp_configure_item*) malloc(item->length);
memcpy(add, item, item->length);
bool status;
if(index < 0)
if (index < 0)
status = fItems.AddItem(add);
else
status = fItems.AddItem(add, index);
if(!status) {
if (!status) {
free(add);
return false;
}
@@ -118,7 +118,7 @@ KPPPConfigurePacket::AddItem(const ppp_configure_item *item, int32 index)
bool
KPPPConfigurePacket::RemoveItem(ppp_configure_item *item)
{
if(!fItems.HasItem(item))
if (!fItems.HasItem(item))
return false;
fItems.RemoveItem(item);
@@ -134,7 +134,7 @@ KPPPConfigurePacket::ItemAt(int32 index) const
{
ppp_configure_item *item = fItems.ItemAt(index);
if(item == fItems.GetDefaultItem())
if (item == fItems.GetDefaultItem())
return NULL;
return item;
@@ -147,9 +147,9 @@ KPPPConfigurePacket::ItemWithType(uint8 type) const
{
ppp_configure_item *item;
for(int32 index = 0; index < CountItems(); index++) {
for (int32 index = 0; index < CountItems(); index++) {
item = ItemAt(index);
if(item && item->type == type)
if (item && item->type == type)
return item;
}
@@ -180,11 +180,11 @@ KPPPConfigurePacket::ToMbuf(uint32 MRU, uint32 reserve)
uint16 length = 0;
ppp_configure_item *item;
for(int32 index = 0; index < CountItems(); index++) {
for (int32 index = 0; index < CountItems(); index++) {
item = ItemAt(index);
// make sure we have enough space left
if(MRU - length < item->length) {
if (MRU - length < item->length) {
m_freem(packet);
return NULL;
}
@@ -1,5 +1,5 @@
/*
* Copyright 2003-2004, Waldemar Kornewald <[email protected]>
* Copyright 2003-2007, Waldemar Kornewald <[email protected]>
* Distributed under the terms of the MIT License.
*/
@@ -40,7 +40,7 @@ KPPPDevice::KPPPDevice(const char *name, uint32 overhead, KPPPInterface& interfa
//! Destructor. Removes device from interface.
KPPPDevice::~KPPPDevice()
{
if(Interface().Device() == this)
if (Interface().Device() == this)
Interface().SetDevice(NULL);
}
@@ -52,21 +52,21 @@ KPPPDevice::~KPPPDevice()
status_t
KPPPDevice::Control(uint32 op, void *data, size_t length)
{
switch(op) {
case PPPC_GET_DEVICE_INFO: {
if(length < sizeof(ppp_device_info_t) || !data)
switch (op) {
case PPPC_GET_DEVICE_INFO:
if (length < sizeof(ppp_device_info_t) || !data)
return B_NO_MEMORY;
ppp_device_info *info = (ppp_device_info*) data;
memset(info, 0, sizeof(ppp_device_info_t));
if(Name())
if (Name())
strncpy(info->name, Name(), PPP_HANDLER_NAME_LENGTH_LIMIT);
info->MTU = MTU();
info->inputTransferRate = InputTransferRate();
info->outputTransferRate = OutputTransferRate();
info->outputBytesCount = CountOutputBytes();
info->isUp = IsUp();
} break;
break;
default:
return B_BAD_VALUE;
@@ -90,7 +90,7 @@ status_t
KPPPDevice::Receive(struct mbuf *packet, uint16 protocolNumber)
{
// let the interface handle the packet
if(protocolNumber == 0)
if (protocolNumber == 0)
return Interface().ReceiveFromDevice(packet);
else
return Interface().Receive(packet, protocolNumber);
File diff suppressed because it is too large Load Diff
@@ -1,5 +1,5 @@
/*
* Copyright 2003-2006, Waldemar Kornewald <[email protected]>
* Copyright 2003-2007, Waldemar Kornewald <[email protected]>
* Distributed under the terms of the MIT License.
*/
@@ -26,7 +26,8 @@
//! Creates a new LCP protocol for the given interface.
KPPPLCP::KPPPLCP(KPPPInterface& interface)
: KPPPProtocol("LCP", PPP_ESTABLISHMENT_PHASE, PPP_LCP_PROTOCOL,
:
KPPPProtocol("LCP", PPP_ESTABLISHMENT_PHASE, PPP_LCP_PROTOCOL,
PPP_PROTOCOL_LEVEL, AF_UNSPEC, 0, interface, NULL, PPP_ALWAYS_ALLOWED),
fStateMachine(interface.StateMachine()),
fTarget(NULL)
@@ -39,9 +40,9 @@ KPPPLCP::KPPPLCP(KPPPInterface& interface)
//! Deletes all added option handlers and LCP extensions.
KPPPLCP::~KPPPLCP()
{
while(CountOptionHandlers())
while (CountOptionHandlers())
delete OptionHandlerAt(0);
while(CountLCPExtensions())
while (CountLCPExtensions())
delete LCPExtensionAt(0);
}
@@ -54,10 +55,10 @@ KPPPLCP::~KPPPLCP()
bool
KPPPLCP::AddOptionHandler(KPPPOptionHandler *optionHandler)
{
if(!optionHandler || &optionHandler->Interface() != &Interface())
if (!optionHandler || &optionHandler->Interface() != &Interface())
return false;
if(Interface().Phase() != PPP_DOWN_PHASE
if (Interface().Phase() != PPP_DOWN_PHASE
|| OptionHandlerFor(optionHandler->Type()))
return false;
// a running connection may not change and there may only be
@@ -74,7 +75,7 @@ KPPPLCP::AddOptionHandler(KPPPOptionHandler *optionHandler)
bool
KPPPLCP::RemoveOptionHandler(KPPPOptionHandler *optionHandler)
{
if(Interface().Phase() != PPP_DOWN_PHASE)
if (Interface().Phase() != PPP_DOWN_PHASE)
return false;
// a running connection may not change
@@ -88,7 +89,7 @@ KPPPLCP::OptionHandlerAt(int32 index) const
{
KPPPOptionHandler *optionHandler = fOptionHandlers.ItemAt(index);
if(optionHandler == fOptionHandlers.GetDefaultItem())
if (optionHandler == fOptionHandlers.GetDefaultItem())
return NULL;
return optionHandler;
@@ -105,14 +106,14 @@ KPPPLCP::OptionHandlerFor(uint8 type, int32 *start) const
int32 index = start ? *start : 0;
if(index < 0)
if (index < 0)
return NULL;
KPPPOptionHandler *current = OptionHandlerAt(index);
for(; current; current = OptionHandlerAt(++index)) {
if(current->Type() == type) {
if(start)
for (; current; current = OptionHandlerAt(++index)) {
if (current->Type() == type) {
if (start)
*start = index;
return current;
}
@@ -129,10 +130,10 @@ KPPPLCP::OptionHandlerFor(uint8 type, int32 *start) const
bool
KPPPLCP::AddLCPExtension(KPPPLCPExtension *lcpExtension)
{
if(!lcpExtension || &lcpExtension->Interface() != &Interface())
if (!lcpExtension || &lcpExtension->Interface() != &Interface())
return false;
if(Interface().Phase() != PPP_DOWN_PHASE)
if (Interface().Phase() != PPP_DOWN_PHASE)
return false;
// a running connection may not change
@@ -147,7 +148,7 @@ KPPPLCP::AddLCPExtension(KPPPLCPExtension *lcpExtension)
bool
KPPPLCP::RemoveLCPExtension(KPPPLCPExtension *lcpExtension)
{
if(Interface().Phase() != PPP_DOWN_PHASE)
if (Interface().Phase() != PPP_DOWN_PHASE)
return false;
// a running connection may not change
@@ -161,7 +162,7 @@ KPPPLCP::LCPExtensionAt(int32 index) const
{
KPPPLCPExtension *lcpExtension = fLCPExtensions.ItemAt(index);
if(lcpExtension == fLCPExtensions.GetDefaultItem())
if (lcpExtension == fLCPExtensions.GetDefaultItem())
return NULL;
return lcpExtension;
@@ -178,14 +179,14 @@ KPPPLCP::LCPExtensionFor(uint8 code, int32 *start) const
int32 index = start ? *start : 0;
if(index < 0)
if (index < 0)
return NULL;
KPPPLCPExtension *current = LCPExtensionAt(index);
for(; current; current = LCPExtensionAt(++index)) {
if(current->Code() == code) {
if(start)
for (; current; current = LCPExtensionAt(++index)) {
if (current->Code() == code) {
if (start)
*start = index;
return current;
}
@@ -201,10 +202,10 @@ KPPPLCP::AdditionalOverhead() const
{
uint32 overhead = Interface().Overhead();
if(Target())
if (Target())
overhead += Target()->Overhead();
if(Interface().Device())
if (Interface().Device())
overhead += Interface().Device()->Overhead();
return overhead;
@@ -231,7 +232,7 @@ KPPPLCP::Down()
status_t
KPPPLCP::Send(struct mbuf *packet, uint16 protocolNumber)
{
if(Target())
if (Target())
return Target()->Send(packet, PPP_LCP_PROTOCOL);
else
return Interface().Send(packet, PPP_LCP_PROTOCOL);
@@ -242,10 +243,10 @@ KPPPLCP::Send(struct mbuf *packet, uint16 protocolNumber)
status_t
KPPPLCP::Receive(struct mbuf *packet, uint16 protocolNumber)
{
if(!packet)
if (!packet)
return B_ERROR;
if(protocolNumber != PPP_LCP_PROTOCOL) {
if (protocolNumber != PPP_LCP_PROTOCOL) {
ERROR("KPPPLCP::Receive(): wrong protocol number!\n");
return PPP_UNHANDLED;
}
@@ -254,59 +255,59 @@ KPPPLCP::Receive(struct mbuf *packet, uint16 protocolNumber)
// remove padding
int32 length = packet->m_len;
if(packet->m_flags & M_PKTHDR)
if (packet->m_flags & M_PKTHDR)
length = packet->m_pkthdr.len;
length -= ntohs(data->length);
if(length)
if (length)
m_adj(packet, -length);
struct mbuf *copy = m_gethdr(MT_DATA);
if(copy) {
if (copy) {
copy->m_data += AdditionalOverhead();
copy->m_pkthdr.len = copy->m_len = packet->m_len;
memcpy(copy->m_data, packet->m_data, copy->m_len);
}
if(ntohs(data->length) < 4)
if (ntohs(data->length) < 4)
return B_ERROR;
bool handled = true;
switch(data->code) {
switch (data->code) {
case PPP_CONFIGURE_REQUEST:
StateMachine().RCREvent(packet);
break;
break;
case PPP_CONFIGURE_ACK:
StateMachine().RCAEvent(packet);
break;
break;
case PPP_CONFIGURE_NAK:
case PPP_CONFIGURE_REJECT:
StateMachine().RCNEvent(packet);
break;
break;
case PPP_TERMINATE_REQUEST:
StateMachine().RTREvent(packet);
break;
break;
case PPP_TERMINATE_ACK:
StateMachine().RTAEvent(packet);
break;
break;
case PPP_CODE_REJECT:
StateMachine().RXJEvent(packet);
break;
break;
case PPP_PROTOCOL_REJECT:
StateMachine().RXJEvent(packet);
break;
break;
case PPP_ECHO_REQUEST:
case PPP_ECHO_REPLY:
case PPP_DISCARD_REQUEST:
StateMachine().RXREvent(packet);
break;
break;
default:
m_freem(packet);
@@ -315,7 +316,7 @@ KPPPLCP::Receive(struct mbuf *packet, uint16 protocolNumber)
packet = copy;
if(!packet)
if (!packet)
return handled ? B_OK : B_ERROR;
status_t result = B_OK;
@@ -324,22 +325,22 @@ KPPPLCP::Receive(struct mbuf *packet, uint16 protocolNumber)
// We must duplicate the packet in order to ask all handlers.
int32 index = 0;
KPPPLCPExtension *lcpExtension = LCPExtensionFor(data->code, &index);
for(; lcpExtension; lcpExtension = LCPExtensionFor(data->code, &(++index))) {
if(!lcpExtension->IsEnabled())
for (; lcpExtension; lcpExtension = LCPExtensionFor(data->code, &(++index))) {
if (!lcpExtension->IsEnabled())
continue;
result = lcpExtension->Receive(packet, data->code);
// check return value and return it on error
if(result == B_OK)
if (result == B_OK)
handled = true;
else if(result != PPP_UNHANDLED) {
else if (result != PPP_UNHANDLED) {
m_freem(packet);
return result;
}
}
if(!handled) {
if (!handled) {
StateMachine().RUCEvent(packet, PPP_LCP_PROTOCOL, PPP_CODE_REJECT);
return PPP_REJECTED;
}
@@ -356,6 +357,6 @@ KPPPLCP::Pulse()
{
StateMachine().TimerEvent();
for(int32 index = 0; index < CountLCPExtensions(); index++)
for (int32 index = 0; index < CountLCPExtensions(); index++)
LCPExtensionAt(index)->Pulse();
}
@@ -1,5 +1,5 @@
/*
* Copyright 2003-2005, Waldemar Kornewald <[email protected]>
* Copyright 2003-2007, Waldemar Kornewald <[email protected]>
* Distributed under the terms of the MIT License.
*/
@@ -10,7 +10,6 @@
*/
#include <KPPPLCPExtension.h>
#include <PPPControl.h>
@@ -31,7 +30,7 @@ KPPPLCPExtension::KPPPLCPExtension(const char *name, uint8 code,
fCode(code),
fEnabled(true)
{
if(name)
if (name)
fName = strdup(name);
else
fName = NULL;
@@ -59,24 +58,26 @@ KPPPLCPExtension::InitCheck() const
status_t
KPPPLCPExtension::Control(uint32 op, void *data, size_t length)
{
switch(op) {
case PPPC_GET_SIMPLE_HANDLER_INFO: {
if(length < sizeof(ppp_simple_handler_info_t) || !data)
switch (op) {
case PPPC_GET_SIMPLE_HANDLER_INFO:
{
if (length < sizeof(ppp_simple_handler_info_t) || !data)
return B_ERROR;
ppp_simple_handler_info *info = (ppp_simple_handler_info*) data;
memset(info, 0, sizeof(ppp_simple_handler_info_t));
if(Name())
if (Name())
strncpy(info->name, Name(), PPP_HANDLER_NAME_LENGTH_LIMIT);
info->isEnabled = IsEnabled();
} break;
break;
}
case PPPC_ENABLE:
if(length < sizeof(uint32) || !data)
if (length < sizeof(uint32) || !data)
return B_ERROR;
SetEnabled(*((uint32*)data));
break;
break;
default:
return B_BAD_VALUE;
@@ -90,7 +91,7 @@ KPPPLCPExtension::Control(uint32 op, void *data, size_t length)
status_t
KPPPLCPExtension::StackControl(uint32 op, void *data)
{
switch(op) {
switch (op) {
default:
return B_BAD_VALUE;
}
@@ -1,5 +1,5 @@
/*
* Copyright 2003-2005, Waldemar Kornewald <[email protected]>
* Copyright 2003-2007, Waldemar Kornewald <[email protected]>
* Distributed under the terms of the MIT License.
*/
@@ -58,13 +58,13 @@ KPPPLayer::InitCheck() const
status_t
KPPPLayer::SendToNext(struct mbuf *packet, uint16 protocolNumber) const
{
if(!packet)
if (!packet)
return B_ERROR;
// Find the next possible handler for this packet.
// Normal protocols (Level() >= PPP_PROTOCOL_LEVEL) do not encapsulate anything.
if(Next()) {
if(Next()->IsAllowedToSend() && Next()->Level() < PPP_PROTOCOL_LEVEL)
if (Next()) {
if (Next()->IsAllowedToSend() && Next()->Level() < PPP_PROTOCOL_LEVEL)
return Next()->Send(packet, protocolNumber);
else
return Next()->SendToNext(packet, protocolNumber);
@@ -93,7 +93,7 @@ KPPPLayer::SetName(const char *name)
{
free(fName);
if(name)
if (name)
fName = strdup(name);
else
fName = NULL;
@@ -1,5 +1,5 @@
/*
* Copyright 2003-2005, Waldemar Kornewald <[email protected]>
* Copyright 2003-2007, Waldemar Kornewald <[email protected]>
* Distributed under the terms of the MIT License.
*/
@@ -24,14 +24,15 @@
\param settings Settings for this handler.
*/
KPPPOptionHandler::KPPPOptionHandler(const char *name, uint8 type,
KPPPInterface& interface, driver_parameter *settings)
: fInitStatus(B_OK),
KPPPInterface& interface, driver_parameter *settings)
:
fInitStatus(B_OK),
fType(type),
fInterface(interface),
fSettings(settings),
fEnabled(true)
{
if(name)
if (name)
fName = strdup(name);
else
fName = NULL;
@@ -59,24 +60,26 @@ KPPPOptionHandler::InitCheck() const
status_t
KPPPOptionHandler::Control(uint32 op, void *data, size_t length)
{
switch(op) {
case PPPC_GET_SIMPLE_HANDLER_INFO: {
if(length < sizeof(ppp_simple_handler_info_t) || !data)
switch (op) {
case PPPC_GET_SIMPLE_HANDLER_INFO:
{
if (length < sizeof(ppp_simple_handler_info_t) || !data)
return B_ERROR;
ppp_simple_handler_info *info = (ppp_simple_handler_info*) data;
memset(info, 0, sizeof(ppp_simple_handler_info_t));
if(Name())
if (Name())
strncpy(info->name, Name(), PPP_HANDLER_NAME_LENGTH_LIMIT);
info->isEnabled = IsEnabled();
} break;
break;
}
case PPPC_ENABLE:
if(length < sizeof(uint32) || !data)
if (length < sizeof(uint32) || !data)
return B_ERROR;
SetEnabled(*((uint32*)data));
break;
break;
default:
return B_BAD_VALUE;
@@ -90,7 +93,7 @@ KPPPOptionHandler::Control(uint32 op, void *data, size_t length)
status_t
KPPPOptionHandler::StackControl(uint32 op, void *data)
{
switch(op) {
switch (op) {
default:
return B_BAD_VALUE;
}
@@ -1,5 +1,5 @@
/*
* Copyright 2003-2004, Waldemar Kornewald <[email protected]>
* Copyright 2003-2007, Waldemar Kornewald <[email protected]>
* Distributed under the terms of the MIT License.
*/
@@ -39,11 +39,12 @@
\param optionHandler Optional handler associated with this protocol.
*/
KPPPProtocol::KPPPProtocol(const char *name, ppp_phase activationPhase,
uint16 protocolNumber, ppp_level level, int32 addressFamily,
uint32 overhead, KPPPInterface& interface,
driver_parameter *settings, int32 flags,
const char *type, KPPPOptionHandler *optionHandler)
: KPPPLayer(name, level, overhead),
uint16 protocolNumber, ppp_level level, int32 addressFamily,
uint32 overhead, KPPPInterface& interface,
driver_parameter *settings, int32 flags,
const char *type, KPPPOptionHandler *optionHandler)
:
KPPPLayer(name, level, overhead),
fActivationPhase(activationPhase),
fProtocolNumber(protocolNumber),
fAddressFamily(addressFamily),
@@ -56,16 +57,16 @@ KPPPProtocol::KPPPProtocol(const char *name, ppp_phase activationPhase,
fUpRequested(true),
fConnectionPhase(PPP_DOWN_PHASE)
{
if(type)
if (type)
fType = strdup(type);
else
fType = NULL;
const char *sideString = get_parameter_value("side", settings);
if(sideString)
if (sideString)
fSide = get_side_string_value(sideString, PPP_LOCAL_SIDE);
else {
if(interface.Mode() == PPP_CLIENT_MODE)
if (interface.Mode() == PPP_CLIENT_MODE)
fSide = PPP_LOCAL_SIDE;
else
fSide = PPP_PEER_SIDE;
@@ -77,7 +78,6 @@ KPPPProtocol::KPPPProtocol(const char *name, ppp_phase activationPhase,
KPPPProtocol::~KPPPProtocol()
{
Interface().RemoveProtocol(this);
free(fType);
}
@@ -100,16 +100,17 @@ KPPPProtocol::Uninit()
status_t
KPPPProtocol::Control(uint32 op, void *data, size_t length)
{
switch(op) {
case PPPC_GET_PROTOCOL_INFO: {
if(length < sizeof(ppp_protocol_info_t) || !data)
switch (op) {
case PPPC_GET_PROTOCOL_INFO:
{
if (length < sizeof(ppp_protocol_info_t) || !data)
return B_ERROR;
ppp_protocol_info *info = (ppp_protocol_info*) data;
memset(info, 0, sizeof(ppp_protocol_info_t));
if(Name())
if (Name())
strncpy(info->name, Name(), PPP_HANDLER_NAME_LENGTH_LIMIT);
if(Type())
if (Type())
strncpy(info->type, Type(), PPP_HANDLER_NAME_LENGTH_LIMIT);
info->activationPhase = ActivationPhase();
info->addressFamily = AddressFamily();
@@ -121,14 +122,15 @@ KPPPProtocol::Control(uint32 op, void *data, size_t length)
info->protocolNumber = ProtocolNumber();
info->isEnabled = IsEnabled();
info->isUpRequested = IsUpRequested();
} break;
break;
}
case PPPC_ENABLE:
if(length < sizeof(uint32) || !data)
if (length < sizeof(uint32) || !data)
return B_ERROR;
SetEnabled(*((uint32*)data));
break;
break;
default:
return B_BAD_VALUE;
@@ -142,7 +144,7 @@ KPPPProtocol::Control(uint32 op, void *data, size_t length)
status_t
KPPPProtocol::StackControl(uint32 op, void *data)
{
switch(op) {
switch (op) {
default:
return B_BAD_VALUE;
}
@@ -160,10 +162,10 @@ KPPPProtocol::SetEnabled(bool enabled)
{
fEnabled = enabled;
if(!enabled) {
if(IsUp() || IsGoingUp())
if (!enabled) {
if (IsUp() || IsGoingUp())
Down();
} else if(!IsUp() && !IsGoingUp() && IsUpRequested() && Interface().IsUp())
} else if (!IsUp() && !IsGoingUp() && IsUpRequested() && Interface().IsUp())
Up();
}
@@ -207,7 +209,6 @@ void
KPPPProtocol::UpFailedEvent()
{
fConnectionPhase = PPP_DOWN_PHASE;
Interface().StateMachine().UpFailedEvent(this);
}
@@ -220,7 +221,6 @@ void
KPPPProtocol::UpEvent()
{
fConnectionPhase = PPP_ESTABLISHED_PHASE;
Interface().StateMachine().UpEvent(this);
}
@@ -233,6 +233,5 @@ void
KPPPProtocol::DownEvent()
{
fConnectionPhase = PPP_DOWN_PHASE;
Interface().StateMachine().DownEvent(this);
}
@@ -1,5 +1,5 @@
/*
* Copyright 2003-2005, Waldemar Kornewald <[email protected]>
* Copyright 2003-2007, Waldemar Kornewald <[email protected]>
* Distributed under the terms of the MIT License.
*/
@@ -42,7 +42,7 @@ KPPPReportManager::KPPPReportManager(BLocker& lock)
//! Deletes all report requests.
KPPPReportManager::~KPPPReportManager()
{
for(int32 index = 0; index < fReportRequests.CountItems(); index++)
for (int32 index = 0; index < fReportRequests.CountItems(); index++)
delete fReportRequests.ItemAt(index);
}
@@ -57,10 +57,10 @@ KPPPReportManager::~KPPPReportManager()
bool
KPPPReportManager::SendReport(thread_id thread, const ppp_report_packet *report)
{
if(!report)
if (!report)
return false;
if(thread == find_thread(NULL)) {
if (thread == find_thread(NULL)) {
report_sender_info *info = new report_sender_info;
info->thread = thread;
memcpy(&info->report, report, sizeof(ppp_report_packet));
@@ -85,7 +85,7 @@ void
KPPPReportManager::EnableReports(ppp_report_type type, thread_id thread,
int32 flags)
{
if(thread < 0 || type == PPP_ALL_REPORTS)
if (thread < 0 || type == PPP_ALL_REPORTS)
return;
LockerHelper locker(fLock);
@@ -103,25 +103,25 @@ KPPPReportManager::EnableReports(ppp_report_type type, thread_id thread,
void
KPPPReportManager::DisableReports(ppp_report_type type, thread_id thread)
{
if(thread < 0)
if (thread < 0)
return;
LockerHelper locker(fLock);
ppp_report_request *request;
for(int32 i = 0; i < fReportRequests.CountItems(); i++) {
for (int32 i = 0; i < fReportRequests.CountItems(); i++) {
request = fReportRequests.ItemAt(i);
if(request->thread != thread)
if (request->thread != thread)
continue;
if(request->type == type || type == PPP_ALL_REPORTS)
if (request->type == type || type == PPP_ALL_REPORTS)
fReportRequests.RemoveItem(request);
}
// empty message queue
while(has_data(thread)) {
while (has_data(thread)) {
thread_id sender;
receive_data(&sender, NULL, 0);
}
@@ -132,17 +132,17 @@ KPPPReportManager::DisableReports(ppp_report_type type, thread_id thread)
bool
KPPPReportManager::DoesReport(ppp_report_type type, thread_id thread)
{
if(thread < 0)
if (thread < 0)
return false;
LockerHelper locker(fLock);
ppp_report_request *request;
for(int32 i = 0; i < fReportRequests.CountItems(); i++) {
for (int32 i = 0; i < fReportRequests.CountItems(); i++) {
request = fReportRequests.ItemAt(i);
if(request->thread == thread && request->type == type)
if (request->thread == thread && request->type == type)
return true;
}
@@ -168,13 +168,13 @@ KPPPReportManager::Report(ppp_report_type type, int32 code, void *data, int32 le
TRACE("KPPPReportManager: Report(type=%d code=%ld length=%ld) to %ld receivers\n",
type, code, length, fReportRequests.CountItems());
if(length > PPP_REPORT_DATA_LIMIT)
if (length > PPP_REPORT_DATA_LIMIT)
return false;
if(fReportRequests.CountItems() == 0)
if (fReportRequests.CountItems() == 0)
return true;
if(!data)
if (!data)
length = 0;
LockerHelper locker(fLock);
@@ -190,22 +190,22 @@ KPPPReportManager::Report(ppp_report_type type, int32 code, void *data, int32 le
ppp_report_request *request;
for(int32 index = 0; index < fReportRequests.CountItems(); index++) {
for (int32 index = 0; index < fReportRequests.CountItems(); index++) {
request = fReportRequests.ItemAt(index);
// do not send to yourself
if(request->thread == me)
if (request->thread == me)
continue;
result = send_data_with_timeout(request->thread, PPP_REPORT_CODE, &report,
sizeof(report), PPP_REPORT_TIMEOUT);
#if DEBUG
if(result == B_TIMED_OUT)
if (result == B_TIMED_OUT)
TRACE("KPPPReportManager::Report(): timed out sending\n");
#endif
if(result == B_BAD_THREAD_ID || result == B_NO_MEMORY
if (result == B_BAD_THREAD_ID || result == B_NO_MEMORY
|| request->flags & PPP_REMOVE_AFTER_REPORT) {
fReportRequests.RemoveItem(request);
--index;
File diff suppressed because it is too large Load Diff
@@ -1,5 +1,5 @@
/*
* Copyright 2003-2005, Waldemar Kornewald <wkornew@gmx.net>
* Copyright 2003-2007, Waldemar Kornewald <wkornew@gmx.net>
* Distributed under the terms of the MIT License.
*/
@@ -13,11 +13,11 @@
bool
IsProtocolAllowed(const KPPPProtocol& protocol)
{
if(protocol.ProtocolNumber() == PPP_LCP_PROTOCOL)
if (protocol.ProtocolNumber() == PPP_LCP_PROTOCOL)
return true;
else if(protocol.Interface().State() != PPP_OPENED_STATE)
else if (protocol.Interface().State() != PPP_OPENED_STATE)
return false;
else if(protocol.Interface().Phase() > PPP_AUTHENTICATION_PHASE
else if (protocol.Interface().Phase() > PPP_AUTHENTICATION_PHASE
|| (protocol.Interface().Phase() >= PPP_ESTABLISHMENT_PHASE
&& protocol.Flags() & PPP_ALWAYS_ALLOWED))
return true;
@@ -30,14 +30,14 @@ status_t
send_data_with_timeout(thread_id thread, int32 code, void *buffer,
size_t buffer_size, uint32 timeout)
{
for(uint32 tries = 0; tries < timeout; tries += 5) {
if(has_data(thread))
for (uint32 tries = 0; tries < timeout; tries += 5) {
if (has_data(thread))
snooze(5000);
else
break;
}
if(!has_data(thread))
if (!has_data(thread))
return send_data(thread, code, buffer, buffer_size);
else
return B_TIMED_OUT;
@@ -49,14 +49,14 @@ receive_data_with_timeout(thread_id *sender, int32 *code, void *buffer,
size_t buffer_size, uint32 timeout)
{
thread_id me = find_thread(NULL);
for(uint32 tries = 0; tries < timeout; tries += 5) {
if(!has_data(me))
for (uint32 tries = 0; tries < timeout; tries += 5) {
if (!has_data(me))
snooze(5000);
else
break;
}
if(has_data(find_thread(NULL))) {
if (has_data(find_thread(NULL))) {
*code = receive_data(sender, buffer, buffer_size);
return B_OK;
} else
@@ -1,5 +1,5 @@
/*
* Copyright 2003-2004, Waldemar Kornewald <wkornew@gmx.net>
* Copyright 2003-2007, Waldemar Kornewald <wkornew@gmx.net>
* Distributed under the terms of the MIT License.
*/
@@ -39,8 +39,8 @@ _KPPPAuthenticationHandler::NextAuthenticator(const KPPPProtocol *start,
// find the next authenticator for side, beginning at start
KPPPProtocol *current = start ? start->NextProtocol() : Interface().FirstProtocol();
for(; current; current = current->NextProtocol()) {
if(current->Type() && !strcasecmp(current->Type(), kAuthenticatorTypeString)
for (; current; current = current->NextProtocol()) {
if (current->Type() && !strcasecmp(current->Type(), kAuthenticatorTypeString)
&& current->OptionHandler() && current->Side() == side)
return current;
}
@@ -56,14 +56,14 @@ _KPPPAuthenticationHandler::AddToRequest(KPPPConfigurePacket& request)
// add an authentication request if needed. This request is added
// by the authenticator's OptionHandler.
if(fPeerAuthenticator)
if (fPeerAuthenticator)
fPeerAuthenticator->SetEnabled(false);
if(fSuggestedPeerAuthenticator)
if (fSuggestedPeerAuthenticator)
fSuggestedPeerAuthenticator->SetEnabled(false);
KPPPProtocol *authenticator;
if(fPeerAuthenticatorRejected) {
if(!fSuggestedPeerAuthenticator) {
if (fPeerAuthenticatorRejected) {
if (!fSuggestedPeerAuthenticator) {
// This happens when the protocol is rejected, but no alternative
// protocol is supplied to us or the suggested protocol is not supported.
// We can use this chance to increase fPeerIndex to the next authenticator.
@@ -73,7 +73,7 @@ _KPPPAuthenticationHandler::AddToRequest(KPPPConfigurePacket& request)
fPeerAuthenticatorRejected = false;
} else {
if(!fPeerAuthenticator) {
if (!fPeerAuthenticator) {
// there is no authenticator selected, so find one for us
authenticator = NextAuthenticator(fPeerAuthenticator, PPP_PEER_SIDE);
} else
@@ -81,8 +81,8 @@ _KPPPAuthenticationHandler::AddToRequest(KPPPConfigurePacket& request)
}
// check if all authenticators were rejected or if no authentication needed
if(!authenticator) {
if(fPeerAuthenticator)
if (!authenticator) {
if (fPeerAuthenticator)
return B_ERROR;
// all authenticators were denied
else
@@ -90,7 +90,7 @@ _KPPPAuthenticationHandler::AddToRequest(KPPPConfigurePacket& request)
// no peer authentication needed
}
if(!authenticator || !authenticator->OptionHandler())
if (!authenticator || !authenticator->OptionHandler())
return B_ERROR;
fPeerAuthenticator = authenticator;
@@ -113,17 +113,17 @@ _KPPPAuthenticationHandler::ParseNak(const KPPPConfigurePacket& nak)
authentication_item *item =
(authentication_item*) nak.ItemWithType(kAuthenticationType);
if(!item)
if (!item)
return B_OK;
// the request was not rejected
if(item->length < 4)
if (item->length < 4)
return B_ERROR;
if(fSuggestedPeerAuthenticator) {
if (fSuggestedPeerAuthenticator) {
fSuggestedPeerAuthenticator->SetEnabled(false);
// if no alternative protocol is supplied we will choose a new one in
// AddToRequest()
if(ntohs(item->protocolNumber) ==
if (ntohs(item->protocolNumber) ==
fSuggestedPeerAuthenticator->ProtocolNumber()) {
fSuggestedPeerAuthenticator = NULL;
return B_OK;
@@ -132,7 +132,7 @@ _KPPPAuthenticationHandler::ParseNak(const KPPPConfigurePacket& nak)
fPeerAuthenticatorRejected = true;
KPPPProtocol *authenticator = Interface().ProtocolFor(ntohs(item->protocolNumber));
if(authenticator && authenticator->Type()
if (authenticator && authenticator->Type()
&& !strcasecmp(authenticator->Type(), kAuthenticatorTypeString)
&& authenticator->OptionHandler())
fSuggestedPeerAuthenticator = authenticator;
@@ -147,7 +147,7 @@ status_t
_KPPPAuthenticationHandler::ParseReject(const KPPPConfigurePacket& reject)
{
// an authentication request must not be rejected!
if(reject.ItemWithType(kAuthenticationType))
if (reject.ItemWithType(kAuthenticationType))
return B_ERROR;
return B_OK;
@@ -160,14 +160,14 @@ _KPPPAuthenticationHandler::ParseAck(const KPPPConfigurePacket& ack)
authentication_item *item =
(authentication_item*) ack.ItemWithType(kAuthenticationType);
if(!item) {
if(fPeerAuthenticator)
if (!item) {
if (fPeerAuthenticator)
return B_ERROR;
// the ack does not contain our request
else
return B_OK;
// no authentication needed
} else if(!fPeerAuthenticator
} else if (!fPeerAuthenticator
|| ntohs(item->protocolNumber) != fPeerAuthenticator->ProtocolNumber())
return B_ERROR;
// this item was never requested
@@ -181,11 +181,11 @@ status_t
_KPPPAuthenticationHandler::ParseRequest(const KPPPConfigurePacket& request,
int32 index, KPPPConfigurePacket& nak, KPPPConfigurePacket& reject)
{
if(fLocalAuthenticator)
if (fLocalAuthenticator)
fLocalAuthenticator->SetEnabled(false);
authentication_item *item = (authentication_item*) request.ItemAt(index);
if(!item)
if (!item)
return B_OK;
// no authentication requested by peer (index > request.CountItems())
@@ -193,7 +193,7 @@ _KPPPAuthenticationHandler::ParseRequest(const KPPPConfigurePacket& request,
// try to find the requested protocol
fLocalAuthenticator = Interface().ProtocolFor(ntohs(item->protocolNumber));
if(fLocalAuthenticator && fLocalAuthenticator->Type()
if (fLocalAuthenticator && fLocalAuthenticator->Type()
&& !strcasecmp(fLocalAuthenticator->Type(), kAuthenticatorTypeString)
&& fLocalAuthenticator->OptionHandler())
return fLocalAuthenticator->OptionHandler()->ParseRequest(request, index,
@@ -203,8 +203,8 @@ _KPPPAuthenticationHandler::ParseRequest(const KPPPConfigurePacket& request,
KPPPProtocol *nextAuthenticator =
NextAuthenticator(fSuggestedLocalAuthenticator, PPP_LOCAL_SIDE);
if(!nextAuthenticator) {
if(!fSuggestedLocalAuthenticator) {
if (!nextAuthenticator) {
if (!fSuggestedLocalAuthenticator) {
// reject the complete authentication option
reject.AddItem((ppp_configure_item*) item);
return B_OK;
@@ -234,17 +234,17 @@ _KPPPAuthenticationHandler::SendingAck(const KPPPConfigurePacket& ack)
authentication_item *item =
(authentication_item*) ack.ItemWithType(kAuthenticationType);
if(!item)
if (!item)
return B_OK;
// no authentication needed
fSuggestedLocalAuthenticator = NULL;
if(!fLocalAuthenticator)
if (!fLocalAuthenticator)
return B_ERROR;
// no authenticator selected (our suggestions must be requested, too)
if(!fLocalAuthenticator)
if (!fLocalAuthenticator)
return B_ERROR;
fLocalAuthenticator->SetEnabled(true);
@@ -256,15 +256,15 @@ _KPPPAuthenticationHandler::SendingAck(const KPPPConfigurePacket& ack)
void
_KPPPAuthenticationHandler::Reset()
{
if(fLocalAuthenticator) {
if (fLocalAuthenticator) {
fLocalAuthenticator->SetEnabled(false);
fLocalAuthenticator->OptionHandler()->Reset();
}
if(fPeerAuthenticator) {
if (fPeerAuthenticator) {
fPeerAuthenticator->SetEnabled(false);
fPeerAuthenticator->OptionHandler()->Reset();
}
if(fSuggestedPeerAuthenticator) {
if (fSuggestedPeerAuthenticator) {
fSuggestedPeerAuthenticator->SetEnabled(false);
fSuggestedPeerAuthenticator->OptionHandler()->Reset();
}
@@ -1,5 +1,5 @@
/*
* Copyright 2003-2004, Waldemar Kornewald <wkornew@gmx.net>
* Copyright 2003-2007, Waldemar Kornewald <wkornew@gmx.net>
* Distributed under the terms of the MIT License.
*/
@@ -32,7 +32,7 @@ _KPPPMRUHandler::_KPPPMRUHandler(KPPPInterface& interface)
status_t
_KPPPMRUHandler::AddToRequest(KPPPConfigurePacket& request)
{
if(!Interface().Device() || Interface().MRU() == 1500)
if (!Interface().Device() || Interface().MRU() == 1500)
return B_OK;
// add MRU request
@@ -48,11 +48,11 @@ status_t
_KPPPMRUHandler::ParseNak(const KPPPConfigurePacket& nak)
{
mru_item *item = (mru_item*) nak.ItemWithType(kMRUType);
if(!item || item->length != 4)
if (!item || item->length != 4)
return B_OK;
uint16 MRU = ntohs(item->MRU);
if(MRU < fLocalMRU)
if (MRU < fLocalMRU)
fLocalMRU = MRU;
return B_OK;
@@ -62,7 +62,7 @@ _KPPPMRUHandler::ParseNak(const KPPPConfigurePacket& nak)
status_t
_KPPPMRUHandler::ParseReject(const KPPPConfigurePacket& reject)
{
if(reject.ItemWithType(kMRUType))
if (reject.ItemWithType(kMRUType))
return B_ERROR;
return B_OK;
@@ -75,10 +75,10 @@ _KPPPMRUHandler::ParseAck(const KPPPConfigurePacket& ack)
uint16 MRU = 1500;
mru_item *item = (mru_item*) ack.ItemWithType(kMRUType);
if(item)
if (item)
MRU = ntohs(item->MRU);
if(MRU < Interface().MRU())
if (MRU < Interface().MRU())
fLocalMRU = MRU;
return B_OK;
@@ -89,7 +89,7 @@ status_t
_KPPPMRUHandler::ParseRequest(const KPPPConfigurePacket& request,
int32 index, KPPPConfigurePacket& nak, KPPPConfigurePacket& reject)
{
if(index == reject.CountItems())
if (index == reject.CountItems())
return B_OK;
return ParseRequestedItem((mru_item*) request.ItemAt(index), Interface());
@@ -111,15 +111,15 @@ ParseRequestedItem(mru_item *item, KPPPInterface& interface)
{
uint16 MRU = 1500;
if(item) {
if(item->length != 4)
if (item) {
if (item->length != 4)
return B_ERROR;
// the request has a corrupted item
MRU = ntohs(item->MRU);
}
if(MRU < interface.MRU())
if (MRU < interface.MRU())
interface.SetMRU(MRU);
return B_OK;
@@ -129,7 +129,7 @@ ParseRequestedItem(mru_item *item, KPPPInterface& interface)
void
_KPPPMRUHandler::Reset()
{
if(Interface().Device()) {
if (Interface().Device()) {
fLocalMRU = Interface().Device()->MTU() - 2;
Interface().SetMRU(fLocalMRU);
} else {
@@ -1,5 +1,5 @@
/*
* Copyright 2003-2004, Waldemar Kornewald <wkornew@gmx.net>
* Copyright 2003-2007, Waldemar Kornewald <wkornew@gmx.net>
* Distributed under the terms of the MIT License.
*/
@@ -24,7 +24,7 @@ status_t
_KPPPPFCHandler::AddToRequest(KPPPConfigurePacket& request)
{
// is PFC not requested or was it rejected?
if(fLocalPFCState == PPP_PFC_REJECTED
if (fLocalPFCState == PPP_PFC_REJECTED
|| (Interface().PFCOptions() & PPP_REQUEST_PFC) == 0)
return B_OK;
@@ -40,7 +40,7 @@ status_t
_KPPPPFCHandler::ParseNak(const KPPPConfigurePacket& nak)
{
// naks do not contain PFC items
if(nak.ItemWithType(kPFCType))
if (nak.ItemWithType(kPFCType))
return B_ERROR;
return B_OK;
@@ -50,10 +50,10 @@ _KPPPPFCHandler::ParseNak(const KPPPConfigurePacket& nak)
status_t
_KPPPPFCHandler::ParseReject(const KPPPConfigurePacket& reject)
{
if(reject.ItemWithType(kPFCType)) {
if (reject.ItemWithType(kPFCType)) {
fLocalPFCState = PPP_PFC_REJECTED;
if(Interface().PFCOptions() & PPP_FORCE_PFC_REQUEST)
if (Interface().PFCOptions() & PPP_FORCE_PFC_REQUEST)
return B_ERROR;
}
@@ -64,12 +64,12 @@ _KPPPPFCHandler::ParseReject(const KPPPConfigurePacket& reject)
status_t
_KPPPPFCHandler::ParseAck(const KPPPConfigurePacket& ack)
{
if(ack.ItemWithType(kPFCType))
if (ack.ItemWithType(kPFCType))
fLocalPFCState = PPP_PFC_ACCEPTED;
else {
fLocalPFCState = PPP_PFC_DISABLED;
if(Interface().PFCOptions() & PPP_FORCE_PFC_REQUEST)
if (Interface().PFCOptions() & PPP_FORCE_PFC_REQUEST)
return B_ERROR;
}
@@ -81,10 +81,10 @@ status_t
_KPPPPFCHandler::ParseRequest(const KPPPConfigurePacket& request,
int32 index, KPPPConfigurePacket& nak, KPPPConfigurePacket& reject)
{
if(!request.ItemWithType(kPFCType))
if (!request.ItemWithType(kPFCType))
return B_OK;
if((Interface().PFCOptions() & PPP_ALLOW_PFC) == 0) {
if ((Interface().PFCOptions() & PPP_ALLOW_PFC) == 0) {
ppp_configure_item item;
item.type = kPFCType;
item.length = 2;
@@ -100,10 +100,10 @@ _KPPPPFCHandler::SendingAck(const KPPPConfigurePacket& ack)
{
ppp_configure_item *item = ack.ItemWithType(kPFCType);
if(item && (Interface().PFCOptions() & PPP_ALLOW_PFC) == 0)
if (item && (Interface().PFCOptions() & PPP_ALLOW_PFC) == 0)
return B_ERROR;
if(item)
if (item)
fPeerPFCState = PPP_PFC_ACCEPTED;
else
fPeerPFCState = PPP_PFC_DISABLED;
@@ -1,5 +1,5 @@
/*
* Copyright 2003-2004, Waldemar Kornewald <wkornew@gmx.net>
* Copyright 2003-2007, Waldemar Kornewald <wkornew@gmx.net>
* Distributed under the terms of the MIT License.
*/
@@ -26,21 +26,21 @@ static const char *sSkipInterfaceParameters[] = {
driver_settings*
dup_driver_settings(const driver_settings *dup)
{
if(!dup)
if (!dup)
return NULL; // we got a NULL pointer, so return nothing
driver_settings *ret = new_driver_settings();
ret->parameter_count = dup->parameter_count;
if(ret->parameter_count > 0) {
if (ret->parameter_count > 0) {
ret->parameters = (driver_parameter*)
malloc(ret->parameter_count * sizeof(driver_parameter));
memset(ret->parameters, 0, ret->parameter_count * sizeof(driver_parameter));
} else
ret->parameters = NULL;
for(int32 index = 0; index < ret->parameter_count; index++)
for (int32 index = 0; index < ret->parameter_count; index++)
copy_driver_parameter(&dup->parameters[index], &ret->parameters[index]);
return ret;
@@ -50,10 +50,10 @@ dup_driver_settings(const driver_settings *dup)
void
free_driver_settings(driver_settings *settings)
{
if(!settings)
if (!settings)
return;
for(int32 index = 0; index < settings->parameter_count; index++)
for (int32 index = 0; index < settings->parameter_count; index++)
free_driver_parameter_fields(&settings->parameters[index]);
free(settings->parameters);
@@ -74,12 +74,12 @@ free_driver_parameter_fields(driver_parameter *parameter)
{
free(parameter->name);
for(int32 index = 0; index < parameter->value_count; index++)
for (int32 index = 0; index < parameter->value_count; index++)
free(parameter->values[index]);
free(parameter->values);
for(int32 index = 0; index < parameter->parameter_count; index++)
for (int32 index = 0; index < parameter->parameter_count; index++)
free_driver_parameter_fields(&parameter->parameters[index]);
free(parameter->parameters);
@@ -111,35 +111,35 @@ new_driver_parameter(const char *name)
bool
copy_driver_parameter(const driver_parameter *from, driver_parameter *to)
{
if(!from || !to)
if (!from || !to)
return false;
free_driver_parameter_fields(to);
if(from->name)
if (from->name)
to->name = strdup(from->name);
else
to->name = NULL;
to->value_count = from->value_count;
if(from->value_count > 0)
if (from->value_count > 0)
to->values = (char**) malloc(from->value_count * sizeof(char*));
else
to->values = NULL;
for(int32 index = 0; index < to->value_count; index++)
for (int32 index = 0; index < to->value_count; index++)
to->values[index] = strdup(from->values[index]);
to->parameter_count = from->parameter_count;
if(to->parameter_count > 0) {
if (to->parameter_count > 0) {
to->parameters =
(driver_parameter*) malloc(to->parameter_count * sizeof(driver_parameter));
memset(to->parameters, 0, to->parameter_count * sizeof(driver_parameter));
} else
to->parameters = NULL;
for(int32 index = 0; index < to->parameter_count; index++)
for (int32 index = 0; index < to->parameter_count; index++)
copy_driver_parameter(&from->parameters[index], &to->parameters[index]);
return true;
@@ -149,12 +149,12 @@ copy_driver_parameter(const driver_parameter *from, driver_parameter *to)
bool
set_driver_parameter_name(const char *name, driver_parameter *parameter)
{
if(!parameter)
if (!parameter)
return false;
free(parameter->name);
if(name)
if (name)
parameter->name = strdup(name);
else
parameter->name = NULL;
@@ -166,7 +166,7 @@ set_driver_parameter_name(const char *name, driver_parameter *parameter)
bool
add_driver_parameter_value(const char *value, driver_parameter *to)
{
if(!value || !to)
if (!value || !to)
return false;
int32 oldCount = to->value_count;
@@ -174,7 +174,7 @@ add_driver_parameter_value(const char *value, driver_parameter *to)
to->values = (char**) malloc((oldCount + 1) * sizeof(char*));
if(!to->values) {
if (!to->values) {
to->values = old;
return false;
}
@@ -190,7 +190,7 @@ add_driver_parameter_value(const char *value, driver_parameter *to)
bool
add_driver_parameter(driver_parameter *add, driver_settings *to)
{
if(!add || !to)
if (!add || !to)
return false;
int32 oldCount = to->parameter_count;
@@ -199,7 +199,7 @@ add_driver_parameter(driver_parameter *add, driver_settings *to)
to->parameters =
(driver_parameter*) malloc((oldCount + 1) * sizeof(driver_parameter));
if(!to->parameters) {
if (!to->parameters) {
to->parameters = old;
return false;
}
@@ -215,16 +215,16 @@ add_driver_parameter(driver_parameter *add, driver_settings *to)
bool
equal_driver_settings(const driver_settings *lhs, const driver_settings *rhs)
{
if(!lhs && !rhs)
if (!lhs && !rhs)
return true;
else if(!lhs || !rhs)
else if (!lhs || !rhs)
return false;
if(lhs->parameter_count != rhs->parameter_count)
if (lhs->parameter_count != rhs->parameter_count)
return false;
for(int32 index = 0; index < lhs->parameter_count; index++) {
if(!equal_driver_parameters(&lhs->parameters[index], &rhs->parameters[index]))
for (int32 index = 0; index < lhs->parameter_count; index++) {
if (!equal_driver_parameters(&lhs->parameters[index], &rhs->parameters[index]))
return false;
}
@@ -235,28 +235,28 @@ equal_driver_settings(const driver_settings *lhs, const driver_settings *rhs)
bool
equal_driver_parameters(const driver_parameter *lhs, const driver_parameter *rhs)
{
if(!lhs && !rhs)
if (!lhs && !rhs)
return true;
else if(!lhs || !rhs)
else if (!lhs || !rhs)
return false;
if(lhs->name && rhs->name) {
if(strcmp(lhs->name, rhs->name))
if (lhs->name && rhs->name) {
if (strcmp(lhs->name, rhs->name))
return false;
} else if(lhs->name != rhs->name)
} else if (lhs->name != rhs->name)
return false;
if(lhs->value_count != rhs->value_count
if (lhs->value_count != rhs->value_count
|| lhs->parameter_count != rhs->parameter_count)
return false;
for(int32 index = 0; index < lhs->value_count; index++) {
if(strcmp(lhs->values[index], rhs->values[index]))
for (int32 index = 0; index < lhs->value_count; index++) {
if (strcmp(lhs->values[index], rhs->values[index]))
return false;
}
for(int32 index = 0; index < lhs->parameter_count; index++) {
if(!equal_driver_parameters(&lhs->parameters[index], &rhs->parameters[index]))
for (int32 index = 0; index < lhs->parameter_count; index++) {
if (!equal_driver_parameters(&lhs->parameters[index], &rhs->parameters[index]))
return false;
}
@@ -267,11 +267,11 @@ equal_driver_parameters(const driver_parameter *lhs, const driver_parameter *rhs
bool
skip_interface_parameter(const driver_parameter *parameter)
{
if(!parameter || !parameter->name)
if (!parameter || !parameter->name)
return false;
for(int32 index = 0; sSkipInterfaceParameters[index]; index++)
if(!strcasecmp(parameter->name, sSkipInterfaceParameters[index]))
for (int32 index = 0; sSkipInterfaceParameters[index]; index++)
if (!strcasecmp(parameter->name, sSkipInterfaceParameters[index]))
return true;
return false;
@@ -281,30 +281,30 @@ skip_interface_parameter(const driver_parameter *parameter)
bool
equal_interface_settings(const driver_settings *lhs, const driver_settings *rhs)
{
if(!lhs && !rhs)
if (!lhs && !rhs)
return true;
else if(!lhs || !rhs)
else if (!lhs || !rhs)
return false;
int32 lhsIndex = 0, rhsIndex = 0;
for(; lhsIndex < lhs->parameter_count; lhsIndex++) {
if(skip_interface_parameter(&lhs->parameters[lhsIndex]))
for (; lhsIndex < lhs->parameter_count; lhsIndex++) {
if (skip_interface_parameter(&lhs->parameters[lhsIndex]))
continue;
for(; rhsIndex < rhs->parameter_count; rhsIndex++)
if(!skip_interface_parameter(&rhs->parameters[rhsIndex]))
for (; rhsIndex < rhs->parameter_count; rhsIndex++)
if (!skip_interface_parameter(&rhs->parameters[rhsIndex]))
break;
if(rhsIndex >= rhs->parameter_count)
if (rhsIndex >= rhs->parameter_count)
return false;
if(!equal_driver_parameters(&lhs->parameters[lhsIndex],
if (!equal_driver_parameters(&lhs->parameters[lhsIndex],
&rhs->parameters[rhsIndex]))
return false;
}
for(; rhsIndex < rhs->parameter_count; rhsIndex++)
if(!skip_interface_parameter(&rhs->parameters[rhsIndex]))
for (; rhsIndex < rhs->parameter_count; rhsIndex++)
if (!skip_interface_parameter(&rhs->parameters[rhsIndex]))
return false;
return true;
@@ -314,17 +314,17 @@ equal_interface_settings(const driver_settings *lhs, const driver_settings *rhs)
ppp_side
get_side_string_value(const char *sideString, ppp_side unknownValue)
{
if(!sideString)
if (!sideString)
return unknownValue;
if(!strcasecmp(sideString, "local"))
if (!strcasecmp(sideString, "local"))
return PPP_LOCAL_SIDE;
if(!strcasecmp(sideString, "peer"))
if (!strcasecmp(sideString, "peer"))
return PPP_PEER_SIDE;
if(!strcasecmp(sideString, "none")
if (!strcasecmp(sideString, "none")
|| !strcasecmp(sideString, "no"))
return PPP_NO_SIDE;
if(!strcasecmp(sideString, "both"))
if (!strcasecmp(sideString, "both"))
return PPP_BOTH_SIDES;
// no correct value has been found => return default value
@@ -335,7 +335,7 @@ get_side_string_value(const char *sideString, ppp_side unknownValue)
bool
get_boolean_value(const char *string, bool unknownValue)
{
if(!string)
if (!string)
return unknownValue;
if (!strcmp(string, "1")
@@ -362,11 +362,11 @@ get_boolean_value(const char *string, bool unknownValue)
const driver_parameter*
get_parameter_with_name(const char *name, const driver_settings *settings)
{
if(!name || !settings)
if (!name || !settings)
return NULL;
for(int32 index = 0; index < settings->parameter_count; index++)
if(!strcasecmp(settings->parameters[index].name, name))
for (int32 index = 0; index < settings->parameter_count; index++)
if (!strcasecmp(settings->parameters[index].name, name))
return &settings->parameters[index];
return NULL;
@@ -378,7 +378,7 @@ get_settings_value(const char *name, const driver_settings *settings)
{
const driver_parameter *parameter = get_parameter_with_name(name, settings);
if(parameter && parameter->value_count > 0 && parameter->values)
if (parameter && parameter->value_count > 0 && parameter->values)
return parameter->values[0];
return NULL;
@@ -1,5 +1,5 @@
/*
* Copyright 2004, Waldemar Kornewald <wkornew@gmx.net>
* Copyright 2004-2007, Waldemar Kornewald <wkornew@gmx.net>
* Distributed under the terms of the MIT License.
*/
@@ -24,10 +24,10 @@ FindMessageParameter(const char *name, const BMessage& message, BMessage *save,
// XXX: this should be removed when we can replace BMessage with something better
BString string;
int32 index = startIndex ? *startIndex : 0;
for(; message.FindMessage(MDSU_PARAMETERS, index, save) == B_OK; index++) {
if(save->FindString(MDSU_NAME, &string) == B_OK
for (; message.FindMessage(MDSU_PARAMETERS, index, save) == B_OK; index++) {
if (save->FindString(MDSU_NAME, &string) == B_OK
&& string.ICompare(name) == 0) {
if(startIndex)
if (startIndex)
*startIndex = index;
return true;
}
@@ -42,9 +42,9 @@ bool
AddValues(const BMessage& message, driver_parameter *parameter)
{
const char *value;
for(int32 index = 0; message.FindString(MDSU_VALUES, index, &value) == B_OK;
for (int32 index = 0; message.FindString(MDSU_VALUES, index, &value) == B_OK;
index++)
if(!add_driver_parameter_value(value, parameter))
if (!add_driver_parameter_value(value, parameter))
return false;
return true;
@@ -55,7 +55,7 @@ inline
bool
AddParameters(const BMessage& message, driver_parameter *to)
{
if(!to)
if (!to)
return false;
return AddParameters(message,
@@ -70,11 +70,11 @@ AddParameters(const BMessage& message, driver_settings *to)
const char *name;
BMessage current;
driver_parameter *parameter;
for(int32 index = 0; message.FindMessage(MDSU_PARAMETERS, index,
for (int32 index = 0; message.FindMessage(MDSU_PARAMETERS, index,
&current) == B_OK; index++) {
name = current.FindString(MDSU_NAME);
parameter = new_driver_parameter(name);
if(!AddValues(current, parameter))
if (!AddValues(current, parameter))
return false;
AddParameters(current, parameter);
@@ -90,7 +90,7 @@ MessageToDriverSettings(const BMessage& message)
{
driver_settings *settings = new_driver_settings();
if(!AddParameters(message, settings)) {
if (!AddParameters(message, settings)) {
free_driver_settings(settings);
return NULL;
}
@@ -103,19 +103,19 @@ static
bool
AddParameter(const driver_parameter *parameter, BMessage *message)
{
if(!parameter || !message)
if (!parameter || !message)
return false;
if(parameter->name)
if (parameter->name)
message->AddString(MDSU_NAME, parameter->name);
else
return false;
for(int32 index = 0; index < parameter->value_count; index++)
if(parameter->values[index])
for (int32 index = 0; index < parameter->value_count; index++)
if (parameter->values[index])
message->AddString(MDSU_VALUES, parameter->values[index]);
for(int32 index = 0; index < parameter->parameter_count; index++) {
for (int32 index = 0; index < parameter->parameter_count; index++) {
BMessage parameterMessage;
AddParameter(&parameter->parameters[index], &parameterMessage);
message->AddMessage(MDSU_PARAMETERS, &parameterMessage);
@@ -128,19 +128,19 @@ AddParameter(const driver_parameter *parameter, BMessage *message)
bool
ReadMessageDriverSettings(const char *name, BMessage *message)
{
if(!name || !message)
if (!name || !message)
return false;
void *handle = load_driver_settings(name);
if(!handle)
if (!handle)
return false;
const driver_settings *settings = get_driver_settings(handle);
if(!settings) {
if (!settings) {
unload_driver_settings(handle);
return false;
}
for(int32 index = 0; index < settings->parameter_count; index++) {
for (int32 index = 0; index < settings->parameter_count; index++) {
BMessage parameter;
AddParameter(&settings->parameters[index], &parameter);
message->AddMessage(MDSU_PARAMETERS, &parameter);
@@ -168,30 +168,30 @@ bool
WriteParameter(BFile& file, const BMessage& parameter, int32 level)
{
const char *name;
if(parameter.FindString(MDSU_NAME, &name) != B_OK || !name)
if (parameter.FindString(MDSU_NAME, &name) != B_OK || !name)
return false;
BString line, word(name);
EscapeWord(word);
bool needsEscaping = word.FindFirst(' ') >= 0;
line.SetTo('\t', level);
if(needsEscaping)
if (needsEscaping)
line << '\"';
line << word;
if(needsEscaping)
if (needsEscaping)
line << '\"';
for(int32 index = 0; parameter.FindString(MDSU_VALUES, index, &name) == B_OK;
for (int32 index = 0; parameter.FindString(MDSU_VALUES, index, &name) == B_OK;
index++)
if(name) {
if (name) {
line << ' ';
word = name;
EscapeWord(word);
needsEscaping = word.FindFirst(' ') >= 0;
if(needsEscaping)
if (needsEscaping)
line << '\"';
line << word;
if(needsEscaping)
if (needsEscaping)
line << '\"';
}
@@ -199,15 +199,15 @@ WriteParameter(BFile& file, const BMessage& parameter, int32 level)
int32 parameterCount;
parameter.GetInfo(MDSU_PARAMETERS, &type, &parameterCount);
if(parameterCount > 0)
if (parameterCount > 0)
line << " {";
line << '\n';
file.Write(line.String(), line.Length());
if(parameterCount > 0) {
if (parameterCount > 0) {
BMessage subParameter;
for(int32 index = 0; parameter.FindMessage(MDSU_PARAMETERS, index,
for (int32 index = 0; parameter.FindMessage(MDSU_PARAMETERS, index,
&subParameter) == B_OK; index++)
WriteParameter(file, subParameter, level + 1);
@@ -223,16 +223,16 @@ WriteParameter(BFile& file, const BMessage& parameter, int32 level)
bool
WriteMessageDriverSettings(BFile& file, const BMessage& message)
{
if(file.InitCheck() != B_OK || !file.IsWritable())
if (file.InitCheck() != B_OK || !file.IsWritable())
return false;
file.SetSize(0);
file.Seek(0, SEEK_SET);
BMessage parameter;
for(int32 index = 0; message.FindMessage(MDSU_PARAMETERS, index, &parameter) == B_OK;
for (int32 index = 0; message.FindMessage(MDSU_PARAMETERS, index, &parameter) == B_OK;
index++) {
if(index > 0)
if (index > 0)
file.Write("\n", 1);
WriteParameter(file, parameter, 0);
}
@@ -1,5 +1,5 @@
/*
* Copyright 2003-2005, Waldemar Kornewald <wkornew@gmx.net>
* Copyright 2003-2007, Waldemar Kornewald <wkornew@gmx.net>
* Distributed under the terms of the MIT License.
*/
@@ -45,7 +45,7 @@ PPPInterface::PPPInterface(const PPPInterface& copy)
//! Destructor.
PPPInterface::~PPPInterface()
{
if(fFD >= 0)
if (fFD >= 0)
close(fFD);
}
@@ -62,9 +62,9 @@ PPPInterface::~PPPInterface()
status_t
PPPInterface::InitCheck() const
{
if(fFD < 0)
if (fFD < 0)
return B_ERROR;
if(fID == PPP_UNDEFINED_INTERFACE_ID)
if (fID == PPP_UNDEFINED_INTERFACE_ID)
return B_BAD_INDEX;
return B_OK;
@@ -87,11 +87,11 @@ PPPInterface::InitCheck() const
status_t
PPPInterface::SetTo(ppp_interface_id ID)
{
if(fFD < 0)
if (fFD < 0)
return B_ERROR;
ppp_interface_info_t info;
if(GetInterfaceInfo(&info)) {
if (GetInterfaceInfo(&info)) {
fName = info.info.name;
fID = ID;
} else {
@@ -119,7 +119,7 @@ PPPInterface::SetTo(ppp_interface_id ID)
status_t
PPPInterface::Control(uint32 op, void *data, size_t length) const
{
if(InitCheck() != B_OK)
if (InitCheck() != B_OK)
return InitCheck();
ppp_control_info control;
@@ -143,7 +143,7 @@ PPPInterface::Control(uint32 op, void *data, size_t length) const
bool
PPPInterface::SetUsername(const char *username) const
{
if(InitCheck() != B_OK || !username)
if (InitCheck() != B_OK || !username)
return false;
return Control(PPPC_SET_USERNAME, const_cast<char*>(username), strlen(username))
@@ -155,7 +155,7 @@ PPPInterface::SetUsername(const char *username) const
bool
PPPInterface::SetPassword(const char *password) const
{
if(InitCheck() != B_OK || !password)
if (InitCheck() != B_OK || !password)
return false;
return Control(PPPC_SET_PASSWORD, const_cast<char*>(password), strlen(password))
@@ -167,7 +167,7 @@ PPPInterface::SetPassword(const char *password) const
bool
PPPInterface::SetAskBeforeConnecting(bool askBeforeConnecting) const
{
if(InitCheck() != B_OK)
if (InitCheck() != B_OK)
return false;
uint32 value = askBeforeConnecting ? 1 : 0;
@@ -188,9 +188,9 @@ PPPInterface::SetAskBeforeConnecting(bool askBeforeConnecting) const
status_t
PPPInterface::GetSettingsEntry(BEntry *entry) const
{
if(InitCheck() != B_OK)
if (InitCheck() != B_OK)
return InitCheck();
else if(!entry || strlen(Name()) == 0)
else if (!entry || strlen(Name()) == 0)
return B_BAD_VALUE;
BDirectory directory(PTP_INTERFACE_SETTINGS_PATH);
@@ -205,7 +205,7 @@ PPPInterface::GetSettingsEntry(BEntry *entry) const
bool
PPPInterface::GetInterfaceInfo(ppp_interface_info_t *info) const
{
if(InitCheck() != B_OK || !info)
if (InitCheck() != B_OK || !info)
return false;
return Control(PPPC_GET_INTERFACE_INFO, &info, sizeof(ppp_interface_info_t))
@@ -222,7 +222,7 @@ PPPInterface::GetInterfaceInfo(ppp_interface_info_t *info) const
bool
PPPInterface::GetStatistics(ppp_statistics *statistics) const
{
if(!statistics)
if (!statistics)
return false;
return Control(PPPC_GET_STATISTICS, statistics, sizeof(ppp_statistics)) == B_OK;
@@ -233,10 +233,10 @@ PPPInterface::GetStatistics(ppp_statistics *statistics) const
bool
PPPInterface::HasSettings(const driver_settings *settings) const
{
if(InitCheck() != B_OK || !settings)
if (InitCheck() != B_OK || !settings)
return false;
if(Control(PPPC_HAS_INTERFACE_SETTINGS, const_cast<driver_settings*>(settings),
if (Control(PPPC_HAS_INTERFACE_SETTINGS, const_cast<driver_settings*>(settings),
sizeof(driver_settings)) == B_OK)
return true;
@@ -248,7 +248,7 @@ PPPInterface::HasSettings(const driver_settings *settings) const
bool
PPPInterface::Up() const
{
if(InitCheck() != B_OK)
if (InitCheck() != B_OK)
return false;
int32 id = ID();
@@ -266,7 +266,7 @@ PPPInterface::Up() const
bool
PPPInterface::Down() const
{
if(InitCheck() != B_OK)
if (InitCheck() != B_OK)
return false;
int32 id = ID();
@@ -1,5 +1,5 @@
/*
* Copyright 2003-2005, Waldemar Kornewald <wkornew@gmx.net>
* Copyright 2003-2007, Waldemar Kornewald <wkornew@gmx.net>
* Distributed under the terms of the MIT License.
*/
@@ -40,22 +40,22 @@ report_thread(void *data)
thread_id sender;
BMessage message;
while(true) {
while (true) {
code = receive_data(&sender, &report, sizeof(report));
if(code == kCodeQuitReportThread)
if (code == kCodeQuitReportThread)
break;
else if(code != PPP_REPORT_CODE)
else if (code != PPP_REPORT_CODE)
continue;
BMessenger messenger(listener->Target());
if(messenger.IsValid()) {
if (messenger.IsValid()) {
message.MakeEmpty();
message.what = PPP_REPORT_MESSAGE;
message.AddInt32("type", report.type);
message.AddInt32("code", report.code);
if(report.length >= sizeof(ppp_interface_id)
if (report.length >= sizeof(ppp_interface_id)
&& ((report.type == PPP_MANAGER_REPORT
&& report.code == PPP_REPORT_INTERFACE_CREATED)
|| report.type >= PPP_INTERFACE_REPORT_TYPE_MIN)) {
@@ -121,7 +121,7 @@ PPPInterfaceListener::~PPPInterfaceListener()
status_t
PPPInterfaceListener::InitCheck() const
{
if(fReportThread < 0)
if (fReportThread < 0)
return B_ERROR;
return Manager().InitCheck();
@@ -147,20 +147,20 @@ PPPInterfaceListener::SetTarget(BHandler *target)
bool
PPPInterfaceListener::WatchInterface(ppp_interface_id ID)
{
if(ID == fInterface)
if (ID == fInterface)
return true;
StopWatchingInterface();
if(ID == PPP_UNDEFINED_INTERFACE_ID)
if (ID == PPP_UNDEFINED_INTERFACE_ID)
return true;
// enable reports
PPPInterface interface(ID);
if(interface.InitCheck() != B_OK)
if (interface.InitCheck() != B_OK)
return false;
if(!interface.EnableReports(PPP_CONNECTION_REPORT, fReportThread, PPP_NO_FLAGS))
if (!interface.EnableReports(PPP_CONNECTION_REPORT, fReportThread, PPP_NO_FLAGS))
return false;
fIsWatching = true;
@@ -185,7 +185,7 @@ PPPInterfaceListener::WatchManager()
void
PPPInterfaceListener::StopWatchingInterface()
{
if(!fIsWatching)
if (!fIsWatching)
return;
PPPInterface interface(fInterface);
@@ -1,5 +1,5 @@
/*
* Copyright 2003-2005, Waldemar Kornewald <wkornew@gmx.net>
* Copyright 2003-2007, Waldemar Kornewald <wkornew@gmx.net>
* Distributed under the terms of the MIT License.
*/
@@ -36,7 +36,7 @@ PPPManager::PPPManager()
//! Destructor.
PPPManager::~PPPManager()
{
if(fFD >= 0)
if (fFD >= 0)
close(fFD);
}
@@ -47,26 +47,26 @@ PPPManager::SetDefaultInterface(const BString name)
{
// load current settings and replace value of "default" with <name>
BMessage settings;
if(!ReadMessageDriverSettings("ptpnet.settings", &settings))
if (!ReadMessageDriverSettings("ptpnet.settings", &settings))
settings.MakeEmpty();
BMessage parameter;
int32 index = 0;
if(FindMessageParameter("default", settings, &parameter, &index))
if (FindMessageParameter("default", settings, &parameter, &index))
settings.RemoveData(MDSU_PARAMETERS, index);
parameter.MakeEmpty();
if(name != "") {
if (name != "") {
parameter.AddString(MDSU_NAME, "default");
parameter.AddString(MDSU_VALUES, name);
settings.AddMessage(MDSU_PARAMETERS, &parameter);
}
BFile file(PTP_SETTINGS_PATH, B_WRITE_ONLY | B_CREATE_FILE | B_ERASE_FILE);
if(file.InitCheck() != B_OK)
if (file.InitCheck() != B_OK)
return false;
if(WriteMessageDriverSettings(file, settings))
if (WriteMessageDriverSettings(file, settings))
return true;
else
return false;
@@ -88,12 +88,12 @@ PPPManager::DefaultInterface()
bool
PPPManager::GetSettingsDirectory(BDirectory *settingsDirectory)
{
if(settingsDirectory) {
if (settingsDirectory) {
BDirectory settings(PTP_INTERFACE_SETTINGS_PATH);
if(settings.InitCheck() != B_OK) {
if (settings.InitCheck() != B_OK) {
create_directory(PTP_INTERFACE_SETTINGS_PATH, 0750);
settings.SetTo(PTP_INTERFACE_SETTINGS_PATH);
if(settings.InitCheck() != B_OK)
if (settings.InitCheck() != B_OK)
return false;
}
@@ -108,7 +108,7 @@ PPPManager::GetSettingsDirectory(BDirectory *settingsDirectory)
status_t
PPPManager::InitCheck() const
{
if(fFD < 0)
if (fFD < 0)
return B_ERROR;
else
return B_OK;
@@ -129,7 +129,7 @@ PPPManager::InitCheck() const
status_t
PPPManager::Control(uint32 op, void *data, size_t length) const
{
if(InitCheck() != B_OK)
if (InitCheck() != B_OK)
return B_ERROR;
control_net_module_args args;
@@ -165,7 +165,7 @@ status_t
PPPManager::ControlModule(const char *name, uint32 op, void *data,
size_t length) const
{
if(!name)
if (!name)
return B_ERROR;
control_net_module_args args;
@@ -189,7 +189,7 @@ PPPManager::CreateInterface(const driver_settings *settings) const
ppp_interface_description_info info;
info.u.settings = settings;
if(Control(PPPC_CREATE_INTERFACE, &info, sizeof(info)) != B_OK)
if (Control(PPPC_CREATE_INTERFACE, &info, sizeof(info)) != B_OK)
return PPP_UNDEFINED_INTERFACE_ID;
else
return info.interface;
@@ -210,7 +210,7 @@ PPPManager::CreateInterfaceWithName(const char *name) const
ppp_interface_description_info info;
info.u.name = name;
if(Control(PPPC_CREATE_INTERFACE_WITH_NAME, &info, sizeof(info)) != B_OK)
if (Control(PPPC_CREATE_INTERFACE_WITH_NAME, &info, sizeof(info)) != B_OK)
return PPP_UNDEFINED_INTERFACE_ID;
else
return info.interface;
@@ -221,7 +221,7 @@ PPPManager::CreateInterfaceWithName(const char *name) const
bool
PPPManager::DeleteInterface(ppp_interface_id ID) const
{
if(Control(PPPC_DELETE_INTERFACE, &ID, sizeof(ID)) != B_OK)
if (Control(PPPC_DELETE_INTERFACE, &ID, sizeof(ID)) != B_OK)
return false;
else
return true;
@@ -251,21 +251,21 @@ PPPManager::Interfaces(int32 *count,
ppp_interface_id *interfaces;
// loop until we get all interfaces
while(true) {
while (true) {
requestCount = *count = CountInterfaces(filter);
if(*count == -1)
if (*count == -1)
return NULL;
requestCount += 10;
// request some more interfaces in case some are added in the mean time
interfaces = new ppp_interface_id[requestCount];
*count = GetInterfaces(interfaces, requestCount, filter);
if(*count == -1) {
if (*count == -1) {
delete interfaces;
return NULL;
}
if(*count < requestCount)
if (*count < requestCount)
break;
delete interfaces;
@@ -285,7 +285,7 @@ PPPManager::GetInterfaces(ppp_interface_id *interfaces, int32 count,
info.count = count;
info.filter = filter;
if(Control(PPPC_GET_INTERFACES, &info, sizeof(info)) != B_OK)
if (Control(PPPC_GET_INTERFACES, &info, sizeof(info)) != B_OK)
return -1;
else
return info.resultCount;
@@ -313,16 +313,16 @@ PPPManager::InterfaceWithUnit(int32 if_unit) const
int32 count;
ppp_interface_id *interfaces = Interfaces(&count, PPP_REGISTERED_INTERFACES);
if(!interfaces)
if (!interfaces)
return PPP_UNDEFINED_INTERFACE_ID;
ppp_interface_id id = PPP_UNDEFINED_INTERFACE_ID;
PPPInterface interface;
ppp_interface_info_t info;
for(int32 index = 0; index < count; index++) {
for (int32 index = 0; index < count; index++) {
interface.SetTo(interfaces[index]);
if(interface.InitCheck() == B_OK && interface.GetInterfaceInfo(&info)
if (interface.InitCheck() == B_OK && interface.GetInterfaceInfo(&info)
&& info.info.if_unit == if_unit) {
id = interface.ID();
break;
@@ -339,22 +339,22 @@ PPPManager::InterfaceWithUnit(int32 if_unit) const
ppp_interface_id
PPPManager::InterfaceWithName(const char *name) const
{
if(!name)
if (!name)
return PPP_UNDEFINED_INTERFACE_ID;
int32 count;
ppp_interface_id *interfaces = Interfaces(&count, PPP_REGISTERED_INTERFACES);
if(!interfaces)
if (!interfaces)
return PPP_UNDEFINED_INTERFACE_ID;
ppp_interface_id id = PPP_UNDEFINED_INTERFACE_ID;
PPPInterface interface;
ppp_interface_info_t info;
for(int32 index = 0; index < count; index++) {
for (int32 index = 0; index < count; index++) {
interface.SetTo(interfaces[index]);
if(interface.InitCheck() == B_OK && interface.GetInterfaceInfo(&info)
if (interface.InitCheck() == B_OK && interface.GetInterfaceInfo(&info)
&& strlen(info.info.name) > 0 && !strcasecmp(info.info.name, name)) {
id = interface.ID();
break;
@@ -363,11 +363,11 @@ PPPManager::InterfaceWithName(const char *name) const
delete interfaces;
if(id != PPP_UNDEFINED_INTERFACE_ID)
if (id != PPP_UNDEFINED_INTERFACE_ID)
return id;
else if(!strncmp(name, "ppp", 3) && strlen(name) > 3 && isdigit(name[3]))
else if (!strncmp(name, "ppp", 3) && strlen(name) > 3 && isdigit(name[3]))
return InterfaceWithUnit(atoi(name + 3));
else if(isdigit(name[0]))
else if (isdigit(name[0]))
return atoi(name);
else
return PPP_UNDEFINED_INTERFACE_ID;
@@ -1,5 +1,5 @@
/*
* Copyright 2003-2004, Waldemar Kornewald <wkornew@gmx.net>
* Copyright 2003-2007, Waldemar Kornewald <wkornew@gmx.net>
* Distributed under the terms of the MIT License.
*/
@@ -16,7 +16,7 @@ get_stack_driver_path()
// user-defined stack driver path?
path = getenv("NET_STACK_DRIVER_PATH");
if(path)
if (path)
return path;
// use the default stack driver path
@@ -1,5 +1,5 @@
/*
* Copyright 2003-2005, Waldemar Kornewald <wkornew@gmx.net>
* Copyright 2003-2007, Waldemar Kornewald <wkornew@gmx.net>
* Distributed under the terms of the MIT License.
*/