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