From abdb7d1abbf1686ecb8f7132e576d332f6cc01ed Mon Sep 17 00:00:00 2001 From: Waldemar Kornewald Date: Mon, 10 Oct 2005 15:11:36 +0000 Subject: [PATCH] - updated email-address - removed profiles, ppp_up, and some TODOs - simplified KPPPReportManager and reports API, KPPPInterface::Up()+Down(), and PPPInterfaceListener (also removed some features from the last one) - KPPPInterface now sends the last PPP_CONNECTION_REPORT message to every newly registered report receiver - added net_server to the build, but removed old net_server testing-stuff all changes are completely untested git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@14338 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- .../network/interfaces/ppp/PPPManager.cpp | 225 ++----- .../network/interfaces/ppp/PPPManager.h | 7 +- .../kernel/network/interfaces/ppp/ppp.cpp | 12 +- src/add-ons/kernel/network/ppp/ipcp/IPCP.h | 2 +- .../kernel/network/ppp/ipcp/Protocol.cpp | 39 +- .../kernel/network/ppp/ipcp/Protocol.h | 4 +- src/add-ons/kernel/network/ppp/ipcp/ipcp.cpp | 2 +- .../kernel/network/ppp/modem/ACFCHandler.cpp | 2 +- .../kernel/network/ppp/modem/ACFCHandler.h | 2 +- src/add-ons/kernel/network/ppp/modem/Modem.h | 2 +- .../kernel/network/ppp/modem/ModemDevice.cpp | 2 +- .../kernel/network/ppp/modem/ModemDevice.h | 2 +- .../kernel/network/ppp/modem/modem.cpp | 2 +- .../kernel/network/ppp/pap/Protocol.cpp | 75 +-- src/add-ons/kernel/network/ppp/pap/Protocol.h | 8 +- src/add-ons/kernel/network/ppp/pap/pap.cpp | 2 +- .../network/ppp/pppoe/DiscoveryPacket.cpp | 2 +- .../network/ppp/pppoe/DiscoveryPacket.h | 2 +- src/add-ons/kernel/network/ppp/pppoe/PPPoE.h | 2 +- .../kernel/network/ppp/pppoe/PPPoEDevice.cpp | 2 +- .../kernel/network/ppp/pppoe/PPPoEDevice.h | 2 +- .../kernel/network/ppp/pppoe/pppoe.cpp | 2 +- .../network/ppp/shared/libkernelppp/Jamfile | 1 - .../libkernelppp/KPPPConfigurePacket.cpp | 2 +- .../ppp/shared/libkernelppp/KPPPDevice.cpp | 2 +- .../ppp/shared/libkernelppp/KPPPInterface.cpp | 401 +++++-------- .../ppp/shared/libkernelppp/KPPPLCP.cpp | 23 +- .../shared/libkernelppp/KPPPLCPExtension.cpp | 15 +- .../ppp/shared/libkernelppp/KPPPLayer.cpp | 15 +- .../shared/libkernelppp/KPPPOptionHandler.cpp | 15 +- .../ppp/shared/libkernelppp/KPPPProfile.cpp | 135 ----- .../ppp/shared/libkernelppp/KPPPProtocol.cpp | 2 +- .../shared/libkernelppp/KPPPReportManager.cpp | 115 ++-- .../shared/libkernelppp/KPPPStateMachine.cpp | 105 ++-- .../ppp/shared/libkernelppp/KPPPUtils.cpp | 5 +- .../network/ppp/shared/libkernelppp/TODO | 3 +- .../_KPPPAuthenticationHandler.cpp | 2 +- .../libkernelppp/_KPPPAuthenticationHandler.h | 2 +- .../shared/libkernelppp/_KPPPMRUHandler.cpp | 2 +- .../ppp/shared/libkernelppp/_KPPPMRUHandler.h | 2 +- .../shared/libkernelppp/_KPPPPFCHandler.cpp | 2 +- .../ppp/shared/libkernelppp/_KPPPPFCHandler.h | 2 +- .../libkernelppp/headers/KPPPInterface.h | 30 +- .../ppp/shared/libkernelppp/headers/KPPPLCP.h | 4 +- .../libkernelppp/headers/KPPPLCPExtension.h | 4 +- .../shared/libkernelppp/headers/KPPPLayer.h | 4 +- .../shared/libkernelppp/headers/KPPPManager.h | 7 +- .../libkernelppp/headers/KPPPOptionHandler.h | 4 +- .../shared/libkernelppp/headers/KPPPProfile.h | 41 -- .../libkernelppp/headers/KPPPReportManager.h | 5 +- .../libkernelppp/headers/KPPPStateMachine.h | 1 + .../libkernelppp/headers/LockerHelper.h | 2 +- .../shared/libkernelppp/headers/PPPControl.h | 14 +- .../ppp/shared/libkernelppp/headers/PPPDefs.h | 9 +- .../libkernelppp/headers/PPPReportDefs.h | 28 +- .../libkernelppp/headers/settings_tools.h | 2 +- .../shared/libkernelppp/settings_tools.cpp | 2 +- .../kernel/network/ppp/shared/libppp/Jamfile | 2 +- .../libppp}/MessageDriverSettingsUtils.cpp | 2 +- .../ppp/shared/libppp/PPPInterface.cpp | 55 +- .../shared/libppp/PPPInterfaceListener.cpp | 186 ++---- .../network/ppp/shared/libppp/PPPManager.cpp | 90 ++- .../ppp/shared/libppp/_libppputils.cpp | 2 +- .../network/ppp/shared/libppp/_libppputils.h | 6 +- .../headers}/MessageDriverSettingsUtils.h | 2 +- .../ppp/shared/libppp/headers/PPPInterface.h | 8 +- .../libppp/headers/PPPInterfaceListener.h | 24 +- .../ppp/shared/libppp/headers/PPPManager.h | 13 +- src/bin/Jamfile | 1 - src/bin/ppp_up/ConnectionView.cpp | 350 ----------- src/bin/ppp_up/ConnectionView.h | 69 --- src/bin/ppp_up/ConnectionWindow.cpp | 51 -- src/bin/ppp_up/ConnectionWindow.h | 29 - src/bin/ppp_up/Jamfile | 29 - src/bin/ppp_up/PPPDeskbarReplicant.cpp | 138 ----- src/bin/ppp_up/PPPDeskbarReplicant.h | 39 -- src/bin/ppp_up/PPPUpAddon.cpp | 307 ---------- src/bin/ppp_up/PPPUpAddon.h | 86 --- src/bin/ppp_up/PPPUpApplication.cpp | 132 ----- src/bin/ppp_up/PPPUpApplication.h | 39 -- src/bin/ppp_up/README | 7 - src/bin/ppp_up/StatusView.cpp | 176 ------ src/bin/ppp_up/StatusView.h | 30 - src/bin/ppp_up/StatusWindow.cpp | 27 - src/bin/ppp_up/StatusWindow.h | 21 - src/bin/ppp_up/TODO | 6 - src/bin/ppp_up/ppp_up.rdef | 37 -- src/servers/Jamfile | 2 +- src/servers/net/Jamfile | 5 - src/servers/net/NetServer.cpp | 2 +- src/servers/net/PPPServer.cpp | 63 +- src/servers/net/PPPServer.h | 11 +- src/servers/net/userland_ipc.c | 554 ------------------ src/servers/net/userland_server.c | 70 --- .../DialUpPreflet/ConnectionOptionsAddon.cpp | 21 +- .../DialUpPreflet/ConnectionOptionsAddon.h | 13 +- .../kits/net/DialUpPreflet/DialUpAddon.h | 28 +- .../net/DialUpPreflet/DialUpApplication.cpp | 2 +- .../kits/net/DialUpPreflet/DialUpView.cpp | 121 ++-- src/tests/kits/net/DialUpPreflet/DialUpView.h | 7 +- .../kits/net/DialUpPreflet/GeneralAddon.cpp | 115 ++-- .../kits/net/DialUpPreflet/GeneralAddon.h | 25 +- .../kits/net/DialUpPreflet/IPCPAddon.cpp | 41 +- src/tests/kits/net/DialUpPreflet/IPCPAddon.h | 13 +- .../kits/net/DialUpPreflet/InterfaceUtils.cpp | 2 +- .../kits/net/DialUpPreflet/InterfaceUtils.h | 2 +- src/tests/kits/net/DialUpPreflet/Jamfile | 30 +- .../kits/net/DialUpPreflet/PPPoEAddon.cpp | 30 +- src/tests/kits/net/DialUpPreflet/PPPoEAddon.h | 13 +- .../kits/net/DialUpPreflet/PTPSettings.cpp | 134 +---- .../kits/net/DialUpPreflet/PTPSettings.h | 23 +- src/tests/kits/net/DialUpPreflet/TODO | 6 +- .../net/DialUpPreflet/TextRequestDialog.cpp | 2 +- .../net/DialUpPreflet/TextRequestDialog.h | 2 +- 114 files changed, 832 insertions(+), 3877 deletions(-) delete mode 100644 src/add-ons/kernel/network/ppp/shared/libkernelppp/KPPPProfile.cpp delete mode 100644 src/add-ons/kernel/network/ppp/shared/libkernelppp/headers/KPPPProfile.h rename src/{tests/kits/net/DialUpPreflet => add-ons/kernel/network/ppp/shared/libppp}/MessageDriverSettingsUtils.cpp (98%) rename src/{tests/kits/net/DialUpPreflet => add-ons/kernel/network/ppp/shared/libppp/headers}/MessageDriverSettingsUtils.h (91%) delete mode 100644 src/bin/ppp_up/ConnectionView.cpp delete mode 100644 src/bin/ppp_up/ConnectionView.h delete mode 100644 src/bin/ppp_up/ConnectionWindow.cpp delete mode 100644 src/bin/ppp_up/ConnectionWindow.h delete mode 100644 src/bin/ppp_up/Jamfile delete mode 100644 src/bin/ppp_up/PPPDeskbarReplicant.cpp delete mode 100644 src/bin/ppp_up/PPPDeskbarReplicant.h delete mode 100644 src/bin/ppp_up/PPPUpAddon.cpp delete mode 100644 src/bin/ppp_up/PPPUpAddon.h delete mode 100644 src/bin/ppp_up/PPPUpApplication.cpp delete mode 100644 src/bin/ppp_up/PPPUpApplication.h delete mode 100644 src/bin/ppp_up/README delete mode 100644 src/bin/ppp_up/StatusView.cpp delete mode 100644 src/bin/ppp_up/StatusView.h delete mode 100644 src/bin/ppp_up/StatusWindow.cpp delete mode 100644 src/bin/ppp_up/StatusWindow.h delete mode 100644 src/bin/ppp_up/TODO delete mode 100644 src/bin/ppp_up/ppp_up.rdef delete mode 100644 src/servers/net/userland_ipc.c delete mode 100644 src/servers/net/userland_server.c diff --git a/src/add-ons/kernel/network/interfaces/ppp/PPPManager.cpp b/src/add-ons/kernel/network/interfaces/ppp/PPPManager.cpp index 72ce4f253b..1d66174da9 100644 --- a/src/add-ons/kernel/network/interfaces/ppp/PPPManager.cpp +++ b/src/add-ons/kernel/network/interfaces/ppp/PPPManager.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2003-2004, Waldemar Kornewald + * Copyright 2003-2005, Waldemar Kornewald * Distributed under the terms of the MIT License. */ @@ -22,63 +22,6 @@ static const char sKPPPIfNameBase[] = "ppp"; -static -status_t -interface_up_thread(void *data) -{ - ppp_interface_entry *entry = (ppp_interface_entry*) data; - - entry->interface->Up(); - --entry->accessing; - - return B_OK; -} - - -static -status_t -bring_interface_up(ppp_interface_entry *entry) -{ - thread_id upThread = spawn_kernel_thread(interface_up_thread, - "PPPManager: up_thread", B_NORMAL_PRIORITY, entry); - resume_thread(upThread); - - return B_OK; -} - - -#if DOWN_AS_THREAD -static -status_t -interface_down_thread(void *data) -{ - ppp_interface_entry *entry = (ppp_interface_entry*) data; - - entry->interface->Down(); - --entry->accessing; - - return B_OK; -} -#endif - - -static -status_t -bring_interface_down(ppp_interface_entry *entry) -{ -#if DOWN_AS_THREAD - thread_id downThread = spawn_kernel_thread(interface_down_thread, - "PPPManager: down_thread", B_NORMAL_PRIORITY, entry); - resume_thread(downThread); */ -#else - entry->interface->Down(); - --entry->accessing; -#endif - - return B_OK; -} - - static status_t deleter_thread(void *data) @@ -138,8 +81,8 @@ PPPManager::~PPPManager() for(int32 index = 0; index < fEntries.CountItems(); index++) { entry = fEntries.ItemAt(index); if(entry) { - free(entry->name); delete entry->interface; + free(entry->name); delete entry; } } @@ -181,13 +124,13 @@ PPPManager::Output(ifnet *ifp, struct mbuf *buf, struct sockaddr *dst, return B_ERROR; } - ++entry->accessing; + atomic_add(entry->accessing, 1); locker.UnlockNow(); if(!entry->interface->DoesConnectOnDemand() && ifp->if_flags & (IFF_UP | IFF_RUNNING) != (IFF_UP | IFF_RUNNING)) { m_freem(buf); - --entry->accessing; + atomic_add(entry->accessing, -1); return ENETDOWN; } @@ -204,12 +147,12 @@ PPPManager::Output(ifnet *ifp, struct mbuf *buf, struct sockaddr *dst, if(result == PPP_UNHANDLED) continue; - --entry->accessing; + atomic_add(entry->accessing, -1); return result; } m_freem(buf); - --entry->accessing; + atomic_add(entry->accessing, -1); return B_ERROR; } @@ -227,7 +170,7 @@ PPPManager::Control(ifnet *ifp, ulong cmd, caddr_t data) } int32 status = B_OK; - ++entry->accessing; + atomic_add(entry->accessing, 1); locker.UnlockNow(); switch(cmd) { @@ -237,38 +180,36 @@ PPPManager::Control(ifnet *ifp, ulong cmd, caddr_t data) && entry->interface->Phase() == PPP_DOWN_PHASE) DeleteInterface(entry->interface->ID()); else - return bring_interface_down(entry); + entry->interface->Down(); } else if(((ifreq*)data)->ifr_flags & IFF_UP) - return bring_interface_up(entry); + entry->interface->Up(); break; default: status = entry->interface->StackControl(cmd, data); } - --entry->accessing; + atomic_add(entry->accessing, -1); return status; } ppp_interface_id PPPManager::CreateInterface(const driver_settings *settings, - const driver_settings *profile = NULL, ppp_interface_id parentID = PPP_UNDEFINED_INTERFACE_ID) { - return _CreateInterface(NULL, settings, profile, parentID); + return _CreateInterface(NULL, settings, parentID); } ppp_interface_id PPPManager::CreateInterfaceWithName(const char *name, - const driver_settings *profile = NULL, ppp_interface_id parentID = PPP_UNDEFINED_INTERFACE_ID) { if(!name) return PPP_UNDEFINED_INTERFACE_ID; - ppp_interface_id result = _CreateInterface(name, NULL, profile, parentID); + ppp_interface_id result = _CreateInterface(name, NULL, parentID); return result; } @@ -292,7 +233,7 @@ PPPManager::DeleteInterface(ppp_interface_id ID) // this check prevents a dead-lock entry->deleting = true; - ++entry->accessing; + atomic_add(entry->accessing, 1); locker.UnlockNow(); // bring interface down if needed @@ -300,7 +241,7 @@ PPPManager::DeleteInterface(ppp_interface_id ID) || entry->interface->Phase() != PPP_DOWN_PHASE) entry->interface->Down(); - --entry->accessing; + atomic_add(entry->accessing, -1); return true; } @@ -420,7 +361,7 @@ PPPManager::Control(uint32 op, void *data, size_t length) if(!info->u.settings) return B_ERROR; - info->interface = CreateInterface(info->u.settings, info->profile); + info->interface = CreateInterface(info->u.settings); // parents cannot be set from userland return info->interface != PPP_UNDEFINED_INTERFACE_ID ? B_OK : B_ERROR; } break; @@ -434,7 +375,7 @@ PPPManager::Control(uint32 op, void *data, size_t length) if(!info->u.name) return B_ERROR; - info->interface = CreateInterfaceWithName(info->u.name, info->profile); + info->interface = CreateInterfaceWithName(info->u.name); // parents cannot be set from userland return info->interface != PPP_UNDEFINED_INTERFACE_ID ? B_OK : B_ERROR; } break; @@ -457,10 +398,11 @@ PPPManager::Control(uint32 op, void *data, size_t length) if(!entry || entry->deleting) return B_BAD_INDEX; - ++entry->accessing; + atomic_add(entry->accessing, 1); locker.UnlockNow(); - return bring_interface_up(entry); + entry->interface->Up(); + atomic_add(entry->accessing, -1); } break; case PPPC_BRING_INTERFACE_DOWN: { @@ -473,10 +415,11 @@ PPPManager::Control(uint32 op, void *data, size_t length) if(!entry || entry->deleting) return B_BAD_INDEX; - ++entry->accessing; + atomic_add(entry->accessing, 1); locker.UnlockNow(); - return bring_interface_down(entry); + entry->interface->Down(); + atomic_add(entry->accessing, -1); } break; case PPPC_CONTROL_INTERFACE: { @@ -564,10 +507,10 @@ PPPManager::ControlInterface(ppp_interface_id ID, uint32 op, void *data, size_t status_t result = B_BAD_INDEX; ppp_interface_entry *entry = EntryFor(ID); if(entry && !entry->deleting) { - ++entry->accessing; + atomic_add(entry->accessing, 1); locker.UnlockNow(); result = entry->interface->Control(op, data, length); - --entry->accessing; + atomic_add(entry->accessing, -1); } return result; @@ -666,7 +609,7 @@ PPPManager::EntryFor(ppp_interface_id ID, int32 *saveIndex = NULL) const ppp_interface_entry *entry; for(int32 index = 0; index < fEntries.CountItems(); index++) { entry = fEntries.ItemAt(index); - if(entry && entry->interface && entry->interface->ID() == ID) { + if(entry && entry->interface->ID() == ID) { if(saveIndex) *saveIndex = index; return entry; @@ -688,7 +631,7 @@ PPPManager::EntryFor(ifnet *ifp, int32 *saveIndex = NULL) const ppp_interface_entry *entry; for(int32 index = 0; index < fEntries.CountItems(); index++) { entry = fEntries.ItemAt(index); - if(entry && entry->interface && entry->interface->Ifnet() == ifp) { + if(entry && entry->interface->Ifnet() == ifp) { if(saveIndex) *saveIndex = index; return entry; @@ -732,8 +675,7 @@ PPPManager::EntryFor(const driver_settings *settings) const ppp_interface_entry *entry; for(int32 index = 0; index < fEntries.CountItems(); index++) { entry = fEntries.ItemAt(index); - if(entry && entry->interface - && equal_interface_settings(entry->interface->Settings(), settings)) + if(entry && equal_interface_settings(entry->interface->Settings(), settings)) return entry; } @@ -754,8 +696,7 @@ PPPManager::SettingsChanged() return; ppp_interface_entry *entry = EntryFor(fDefaultInterface); - if(entry && entry->interface - && entry->interface->StateMachine().Phase() == PPP_DOWN_PHASE) + if(entry && entry->interface->StateMachine().Phase() == PPP_DOWN_PHASE) DeleteInterface(entry->interface->ID()); free(fDefaultInterface); @@ -767,7 +708,7 @@ PPPManager::SettingsChanged() fDefaultInterface = strdup(name); ppp_interface_id id = CreateInterfaceWithName(name); entry = EntryFor(id); - if(entry && entry->interface) + if(entry) entry->interface->SetConnectOnDemand(true); } @@ -782,8 +723,8 @@ greater(const void *a, const void *b) // used by the public CreateInterface() methods ppp_interface_id -PPPManager::_CreateInterface(const char *name, const driver_settings *settings, - const driver_settings *profile, ppp_interface_id parentID) +PPPManager::_CreateInterface(const char *name, + const driver_settings *settings, ppp_interface_id parentID) { TRACE("PPPManager: CreateInterface(%s)\n", name ? name : "Unnamed"); @@ -800,85 +741,35 @@ PPPManager::_CreateInterface(const char *name, const driver_settings *settings, // check if we already have an entry for the named interface ppp_interface_entry *entry = EntryFor(name); - if(entry) { - if(entry->interface) - return entry->interface->ID(); - // already existing interfaces do not need a PPP team - - ++entry->accessing; - - thread_info info; - if(get_thread_info(entry->requestThread, &info) != B_OK) - entry->requestThread = -1; - else { - // test if app is responsive (i.e.: it reacts in at most 0.5secs) - thread_id sender; - int32 code; - if(send_data_with_timeout(entry->requestThread, PPP_RESPONSE_TEST_CODE, - NULL, 0, PPP_REPORT_TIMEOUT) != B_OK - || receive_data_with_timeout(&sender, &code, NULL, 0, 500) - != B_OK || code != B_OK) { - entry->requestThread = -1; - kill_team(info.team); - } - } - } else { - entry = new ppp_interface_entry; - entry->name = name ? strdup(name) : NULL; - entry->accessing = 1; - entry->requestThread = -1; - fEntries.AddItem(entry); - // nothing bad can happen because we are in a locked section - } + if(entry) + return entry->interface->ID(); + entry = new ppp_interface_entry; + entry->name = name ? strdup(name) : NULL; + entry->accessing = 1; entry->deleting = false; + entry->requestThread = -1; + fEntries.AddItem(entry); + // nothing bad can happen because we are in a locked section - new KPPPInterface(name, entry, id, settings, profile, + new KPPPInterface(name, entry, id, settings, parentEntry ? parentEntry->interface : NULL); // KPPPInterface will add itself to the entry (no need to do it here) if(entry->interface->InitCheck() != B_OK) { - // use safe code because entry might have existed before this method call - --entry->accessing; - entry->deleting = true; - if(entry->accessing > 0) - return PPP_UNDEFINED_INTERFACE_ID; - - free(entry->name); delete entry->interface; + free(entry->name); fEntries.RemoveItem(entry); delete entry; return PPP_UNDEFINED_INTERFACE_ID; } - // run ppp_up and enable reports for the request window (DONE?) - if(entry->requestThread < 0 && name) { - const char *argv[] = { "/boot/beos/bin/ppp_up", name, NULL }; - const char *env[] = { NULL }; - thread_id app = load_image(2, argv, env); - if(app < 0) - ERROR("KPPPInterface::Up(): Error: could not load ppp_up!\n"); - resume_thread(app); - - // XXX: Sending to a thread does not work immediately. So, we wait... - snooze(150000); - - if(send_data(app, 0, &id, sizeof(id)) < B_OK) - ERROR("KPPPInterface::Up(): Error: could not send to ppp_up!\n"); - - // register the request thread as a report receiver - receive_data(&entry->requestThread, NULL, 0); - } - if(entry->requestThread >= 0) - entry->interface->ReportManager().EnableReports(PPP_CONNECTION_REPORT, - entry->requestThread, PPP_WAIT_FOR_REPLY | PPP_NO_REPLY_TIMEOUT); - locker.UnlockNow(); // it is safe to access the manager from userland now if(!Report(PPP_MANAGER_REPORT, PPP_REPORT_INTERFACE_CREATED, &id, sizeof(ppp_interface_id))) { DeleteInterface(id); - --entry->accessing; + atomic_add(entry->accessing, -1); return PPP_UNDEFINED_INTERFACE_ID; } @@ -886,7 +777,7 @@ PPPManager::_CreateInterface(const char *name, const driver_settings *settings, entry->interface->StateMachine().DownProtocols(); entry->interface->StateMachine().ResetLCPHandlers(); - --entry->accessing; + atomic_add(entry->accessing, -1); return id; } @@ -901,7 +792,7 @@ PPPManager::FindUnit() const ppp_interface_entry *entry; for(int32 index = 0; index < fEntries.CountItems(); index++) { entry = fEntries.ItemAt(index); - if(entry && entry->interface && entry->interface->Ifnet()) + if(entry && entry->interface->Ifnet()) units[index] = entry->interface->Ifnet()->if_unit; else units[index] = -1; @@ -933,39 +824,21 @@ PPPManager::DeleterThreadEvent() ppp_interface_entry *entry; for(int32 index = 0; index < fEntries.CountItems(); index++) { entry = fEntries.ItemAt(index); - if(!entry) { + if(entry && entry->deleting && entry->accessing <= 0) { + delete entry->interface; fEntries.RemoveItem(index); --index; - continue; - } - - if(entry->deleting && entry->accessing <= 0) { - // XXX: check twice if it is safe to delete the interface - // such that it is reused by _CreateInterface() - delete entry->interface; - entry->interface = NULL; - - // only remove entries that do not have ppp_up associated with them - if(entry->requestThread >= 0) { - thread_info info; - if(get_thread_info(entry->requestThread, &info) == B_OK) - continue; - } // recreate default interface if(entry->name && fDefaultInterface && !strcmp(entry->name, fDefaultInterface)) { + free(fDefaultInterface); + fDefaultInterface = NULL; SettingsChanged(); - CreateInterfaceWithName(fDefaultInterface); - if(entry->interface) - entry->interface->SetConnectOnDemand(true); - continue; } free(entry->name); delete entry; - fEntries.RemoveItem(index); - --index; } } } @@ -979,7 +852,7 @@ PPPManager::Pulse() ppp_interface_entry *entry; for(int32 index = 0; index < fEntries.CountItems(); index++) { entry = fEntries.ItemAt(index); - if(entry && entry->interface) + if(entry) entry->interface->Pulse(); } } diff --git a/src/add-ons/kernel/network/interfaces/ppp/PPPManager.h b/src/add-ons/kernel/network/interfaces/ppp/PPPManager.h index c31747f377..41d3afaa49 100644 --- a/src/add-ons/kernel/network/interfaces/ppp/PPPManager.h +++ b/src/add-ons/kernel/network/interfaces/ppp/PPPManager.h @@ -1,5 +1,5 @@ /* - * Copyright 2003-2004, Waldemar Kornewald + * Copyright 2003-2005, Waldemar Kornewald * Distributed under the terms of the MIT License. */ @@ -29,10 +29,8 @@ class PPPManager { int32 Control(ifnet *ifp, ulong cmd, caddr_t data); ppp_interface_id CreateInterface(const driver_settings *settings, - const driver_settings *profile = NULL, ppp_interface_id parentID = PPP_UNDEFINED_INTERFACE_ID); ppp_interface_id CreateInterfaceWithName(const char *name, - const driver_settings *profile = NULL, ppp_interface_id parentID = PPP_UNDEFINED_INTERFACE_ID); bool DeleteInterface(ppp_interface_id ID); bool RemoveInterface(ppp_interface_id ID); @@ -70,8 +68,7 @@ class PPPManager { private: ppp_interface_id _CreateInterface(const char *name, - const driver_settings *settings, const driver_settings *profile, - ppp_interface_id parentID); + const driver_settings *settings, ppp_interface_id parentID); int32 FindUnit() const; private: diff --git a/src/add-ons/kernel/network/interfaces/ppp/ppp.cpp b/src/add-ons/kernel/network/interfaces/ppp/ppp.cpp index 83f7f9c363..90205e8fbc 100644 --- a/src/add-ons/kernel/network/interfaces/ppp/ppp.cpp +++ b/src/add-ons/kernel/network/interfaces/ppp/ppp.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2003-2004, Waldemar Kornewald + * Copyright 2003-2005, Waldemar Kornewald * Distributed under the terms of the MIT License. */ @@ -86,11 +86,10 @@ ppp_control(uint32 op, void *data, size_t length) static ppp_interface_id -CreateInterface(const driver_settings *settings, const driver_settings *profile, - ppp_interface_id parent) +CreateInterface(const driver_settings *settings, ppp_interface_id parent) { if(sManager) - return sManager->CreateInterface(settings, profile, parent); + return sManager->CreateInterface(settings, parent); else return PPP_UNDEFINED_INTERFACE_ID; } @@ -98,11 +97,10 @@ CreateInterface(const driver_settings *settings, const driver_settings *profile, static ppp_interface_id -CreateInterfaceWithName(const char *name, const driver_settings *profile, - ppp_interface_id parent) +CreateInterfaceWithName(const char *name, ppp_interface_id parent) { if(sManager) - return sManager->CreateInterfaceWithName(name, profile, parent); + return sManager->CreateInterfaceWithName(name, parent); else return PPP_UNDEFINED_INTERFACE_ID; } diff --git a/src/add-ons/kernel/network/ppp/ipcp/IPCP.h b/src/add-ons/kernel/network/ppp/ipcp/IPCP.h index 71a59379b0..c807af8d89 100644 --- a/src/add-ons/kernel/network/ppp/ipcp/IPCP.h +++ b/src/add-ons/kernel/network/ppp/ipcp/IPCP.h @@ -1,5 +1,5 @@ /* - * Copyright 2003-2004, Waldemar Kornewald + * Copyright 2003-2004, Waldemar Kornewald * Distributed under the terms of the MIT License. */ diff --git a/src/add-ons/kernel/network/ppp/ipcp/Protocol.cpp b/src/add-ons/kernel/network/ppp/ipcp/Protocol.cpp index 7a1b451951..679e1950c4 100644 --- a/src/add-ons/kernel/network/ppp/ipcp/Protocol.cpp +++ b/src/add-ons/kernel/network/ppp/ipcp/Protocol.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2003-2004, Waldemar Kornewald + * Copyright 2003-2005, Waldemar Kornewald * Distributed under the terms of the MIT License. */ @@ -75,7 +75,20 @@ IPCP::IPCP(KPPPInterface& interface, driver_parameter *settings) fNextTimeout(0), fLock("IPCP") { - ProfileChanged(); + // reset configurations + memset(&fLocalConfiguration, 0, sizeof(ipcp_configuration)); + memset(&fPeerConfiguration, 0, sizeof(ipcp_configuration)); + + // reset requests + memset(&fLocalRequests, 0, sizeof(ipcp_requests)); + memset(&fPeerRequests, 0, sizeof(ipcp_requests)); + + // Parse settings: + // "Local" and "Peer" describe each side's settings + ParseSideRequests(get_parameter_with_name(IPCP_LOCAL_SIDE_KEY, Settings()), + PPP_LOCAL_SIDE); + ParseSideRequests(get_parameter_with_name(IPCP_PEER_SIDE_KEY, Settings()), + PPP_PEER_SIDE); #if DEBUG sFD = open("/boot/home/ipcpdebug", O_WRONLY | O_CREAT | O_TRUNC); @@ -128,28 +141,6 @@ IPCP::StackControl(uint32 op, void *data) } -void -IPCP::ProfileChanged() -{ - // reset configurations - memset(&fLocalConfiguration, 0, sizeof(ipcp_configuration)); - memset(&fPeerConfiguration, 0, sizeof(ipcp_configuration)); - - // reset requests - memset(&fLocalRequests, 0, sizeof(ipcp_requests)); - memset(&fPeerRequests, 0, sizeof(ipcp_requests)); - - // Parse settings: - // "Local" and "Peer" describe each side's settings - const driver_parameter *profile - = Interface().Profile().SettingsFor("protocol", "ipcp"); - ParseSideRequests(get_parameter_with_name(IPCP_LOCAL_SIDE_KEY, profile), - PPP_LOCAL_SIDE); - ParseSideRequests(get_parameter_with_name(IPCP_PEER_SIDE_KEY, profile), - PPP_PEER_SIDE); -} - - bool IPCP::Up() { diff --git a/src/add-ons/kernel/network/ppp/ipcp/Protocol.h b/src/add-ons/kernel/network/ppp/ipcp/Protocol.h index d25e530a53..96030944f1 100644 --- a/src/add-ons/kernel/network/ppp/ipcp/Protocol.h +++ b/src/add-ons/kernel/network/ppp/ipcp/Protocol.h @@ -1,5 +1,5 @@ /* - * Copyright 2003-2004, Waldemar Kornewald + * Copyright 2003-2005, Waldemar Kornewald * Distributed under the terms of the MIT License. */ @@ -68,8 +68,6 @@ class IPCP : public KPPPProtocol { virtual status_t StackControl(uint32 op, void *data); - virtual void ProfileChanged(); - virtual bool Up(); virtual bool Down(); diff --git a/src/add-ons/kernel/network/ppp/ipcp/ipcp.cpp b/src/add-ons/kernel/network/ppp/ipcp/ipcp.cpp index fff51ee3cb..fbf413787f 100644 --- a/src/add-ons/kernel/network/ppp/ipcp/ipcp.cpp +++ b/src/add-ons/kernel/network/ppp/ipcp/ipcp.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2003-2004, Waldemar Kornewald + * Copyright 2003-2004, Waldemar Kornewald * Distributed under the terms of the MIT License. */ diff --git a/src/add-ons/kernel/network/ppp/modem/ACFCHandler.cpp b/src/add-ons/kernel/network/ppp/modem/ACFCHandler.cpp index c5fdb6c6ad..4b333ee812 100644 --- a/src/add-ons/kernel/network/ppp/modem/ACFCHandler.cpp +++ b/src/add-ons/kernel/network/ppp/modem/ACFCHandler.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2003-2004, Waldemar Kornewald + * Copyright 2003-2004, Waldemar Kornewald * Distributed under the terms of the MIT License. */ diff --git a/src/add-ons/kernel/network/ppp/modem/ACFCHandler.h b/src/add-ons/kernel/network/ppp/modem/ACFCHandler.h index 4a5156ecbb..1245ac42ed 100644 --- a/src/add-ons/kernel/network/ppp/modem/ACFCHandler.h +++ b/src/add-ons/kernel/network/ppp/modem/ACFCHandler.h @@ -1,5 +1,5 @@ /* - * Copyright 2003-2004, Waldemar Kornewald + * Copyright 2003-2004, Waldemar Kornewald * Distributed under the terms of the MIT License. */ diff --git a/src/add-ons/kernel/network/ppp/modem/Modem.h b/src/add-ons/kernel/network/ppp/modem/Modem.h index 2a2906fbdc..9e9037332b 100644 --- a/src/add-ons/kernel/network/ppp/modem/Modem.h +++ b/src/add-ons/kernel/network/ppp/modem/Modem.h @@ -1,5 +1,5 @@ /* - * Copyright 2003-2004, Waldemar Kornewald + * Copyright 2003-2004, Waldemar Kornewald * Distributed under the terms of the MIT License. */ diff --git a/src/add-ons/kernel/network/ppp/modem/ModemDevice.cpp b/src/add-ons/kernel/network/ppp/modem/ModemDevice.cpp index 5666d02989..0cb7494c9b 100644 --- a/src/add-ons/kernel/network/ppp/modem/ModemDevice.cpp +++ b/src/add-ons/kernel/network/ppp/modem/ModemDevice.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2003-2004, Waldemar Kornewald + * Copyright 2003-2004, Waldemar Kornewald * Distributed under the terms of the MIT License. */ diff --git a/src/add-ons/kernel/network/ppp/modem/ModemDevice.h b/src/add-ons/kernel/network/ppp/modem/ModemDevice.h index 180078833a..f885fb36e6 100644 --- a/src/add-ons/kernel/network/ppp/modem/ModemDevice.h +++ b/src/add-ons/kernel/network/ppp/modem/ModemDevice.h @@ -1,5 +1,5 @@ /* - * Copyright 2003-2004, Waldemar Kornewald + * Copyright 2003-2004, Waldemar Kornewald * Distributed under the terms of the MIT License. */ diff --git a/src/add-ons/kernel/network/ppp/modem/modem.cpp b/src/add-ons/kernel/network/ppp/modem/modem.cpp index bda3db6f0a..542a0b54ac 100644 --- a/src/add-ons/kernel/network/ppp/modem/modem.cpp +++ b/src/add-ons/kernel/network/ppp/modem/modem.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2003-2004, Waldemar Kornewald + * Copyright 2003-2004, Waldemar Kornewald * Distributed under the terms of the MIT License. */ diff --git a/src/add-ons/kernel/network/ppp/pap/Protocol.cpp b/src/add-ons/kernel/network/ppp/pap/Protocol.cpp index 31e7eaa3d1..45b5bf66cd 100644 --- a/src/add-ons/kernel/network/ppp/pap/Protocol.cpp +++ b/src/add-ons/kernel/network/ppp/pap/Protocol.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2003-2004, Waldemar Kornewald + * Copyright 2003-2005, Waldemar Kornewald * Distributed under the terms of the MIT License. */ @@ -84,7 +84,6 @@ PAP::PAP(KPPPInterface& interface, driver_parameter *settings) fNextTimeout(0), fLock("PAP") { - ProfileChanged(); } @@ -103,13 +102,6 @@ PAP::InitCheck() const } -void -PAP::ProfileChanged() -{ - ParseSettings(Interface().Profile().SettingsFor("authenticator", "pap")); -} - - bool PAP::Up() { @@ -262,36 +254,6 @@ PAP::Pulse() } -bool -PAP::ParseSettings(const driver_parameter *requests) -{ - memset(fUser, 0, sizeof(fUser)); - memset(fPassword, 0, sizeof(fPassword)); - - if(!requests) - return false; - - // The following values are allowed: - // "User" - // "Password" - - for(int32 index = 0; index < requests->parameter_count; index++) { - if(requests->parameters[index].value_count == 0) - continue; - - // ignore user and password if too long (255 chars at max) - if(!strcasecmp(requests->parameters[index].name, "User") - && strlen(requests->parameters[index].values[0]) < sizeof(fUser)) - strcpy(fUser, requests->parameters[index].values[0]); - else if(!strcasecmp(requests->parameters[index].name, "Password") - && strlen(requests->parameters[index].values[0]) < sizeof(fPassword)) - strcpy(fPassword, requests->parameters[index].values[0]); - } - - return true; -} - - uint8 PAP::NextID() { @@ -359,9 +321,11 @@ PAP::TOBadEvent() NewState(INITIAL); locker.UnlockNow(); if(State() == REQ_SENT) - Interface().StateMachine().LocalAuthenticationDenied(fUser); + Interface().StateMachine().LocalAuthenticationDenied( + Interface().Username()); else - Interface().StateMachine().PeerAuthenticationDenied(fUser); + Interface().StateMachine().PeerAuthenticationDenied( + Interface().Username()); UpFailedEvent(); break; @@ -391,11 +355,14 @@ PAP::RREvent(struct mbuf *packet) return; } - char *user = (char*) userLength + 1, *password = (char*) passwordLength + 1; + char *peerUsername = (char*) userLength + 1, + *peerPassword = (char*) passwordLength + 1; + const char *username = Interface().Username(), *password = Interface().Password(); - if(*userLength == strlen(fUser) && *passwordLength == strlen(fPassword) - && !strncmp(user, fUser, *userLength) - && !strncmp(password, fPassword, *passwordLength)) { + + if(*userLength == strlen(username) && *passwordLength == strlen(password) + && !strncmp(peerUsername, username, *userLength) + && !strncmp(peerPassword, password, *passwordLength)) { NewState(ACCEPTED); locker.UnlockNow(); Interface().StateMachine().PeerAuthenticationAccepted(user); @@ -430,7 +397,8 @@ PAP::RAEvent(struct mbuf *packet) case REQ_SENT: NewState(ACCEPTED); locker.UnlockNow(); - Interface().StateMachine().LocalAuthenticationAccepted(fUser); + Interface().StateMachine().LocalAuthenticationAccepted( + Interface().Username()); UpEvent(); break; @@ -461,7 +429,8 @@ PAP::RNEvent(struct mbuf *packet) case REQ_SENT: NewState(INITIAL); locker.UnlockNow(); - Interface().StateMachine().LocalAuthenticationDenied(fUser); + Interface().StateMachine().LocalAuthenticationDenied( + Interface().Username()); UpFailedEvent(); break; @@ -494,7 +463,9 @@ PAP::SendRequest() if(!packet) return false; - packet->m_pkthdr.len = packet->m_len = 6 + strlen(fUser) + strlen(fPassword); + const char *username = Interface().Username(), *password = Interface().Password(); + + packet->m_pkthdr.len = packet->m_len = 6 + strlen(username) + strlen(password); // reserve some space for overhead (we are lazy and reserve too much) packet->m_data += Interface().PacketOverhead(); @@ -504,10 +475,10 @@ PAP::SendRequest() request->id = fRequestID = NextID(); request->length = htons(packet->m_len); uint8 *data = request->data; - data[0] = strlen(fUser); - memcpy(data + 1, fUser, strlen(fUser)); - data[1 + data[0]] = strlen(fPassword); - memcpy(data + 2 + data[0], fPassword, strlen(fPassword)); + data[0] = strlen(username); + memcpy(data + 1, username, strlen(username)); + data[1 + data[0]] = strlen(password); + memcpy(data + 2 + data[0], password, strlen(password)); return Interface().Send(packet, PAP_PROTOCOL) == B_OK; } diff --git a/src/add-ons/kernel/network/ppp/pap/Protocol.h b/src/add-ons/kernel/network/ppp/pap/Protocol.h index 17c6c90d00..b925a2a542 100644 --- a/src/add-ons/kernel/network/ppp/pap/Protocol.h +++ b/src/add-ons/kernel/network/ppp/pap/Protocol.h @@ -1,5 +1,5 @@ /* - * Copyright 2003-2004, Waldemar Kornewald + * Copyright 2003-2005, Waldemar Kornewald * Distributed under the terms of the MIT License. */ @@ -54,8 +54,6 @@ class PAP : public KPPPProtocol { pap_state State() const { return fState; } - virtual void ProfileChanged(); - virtual bool Up(); virtual bool Down(); @@ -64,8 +62,6 @@ class PAP : public KPPPProtocol { virtual void Pulse(); private: - bool ParseSettings(const driver_parameter *settings); - // for state machine void NewState(pap_state next); uint8 NextID(); @@ -88,8 +84,6 @@ class PAP : public KPPPProtocol { bool SendNak(struct mbuf *packet); private: - char fUser[256], fPassword[256]; - // for state machine pap_state fState; vint32 fID; diff --git a/src/add-ons/kernel/network/ppp/pap/pap.cpp b/src/add-ons/kernel/network/ppp/pap/pap.cpp index b3cb529864..5805238bdb 100644 --- a/src/add-ons/kernel/network/ppp/pap/pap.cpp +++ b/src/add-ons/kernel/network/ppp/pap/pap.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2003-2004, Waldemar Kornewald + * Copyright 2003-2004, Waldemar Kornewald * Distributed under the terms of the MIT License. */ diff --git a/src/add-ons/kernel/network/ppp/pppoe/DiscoveryPacket.cpp b/src/add-ons/kernel/network/ppp/pppoe/DiscoveryPacket.cpp index 44ef7cf906..fa873c0952 100644 --- a/src/add-ons/kernel/network/ppp/pppoe/DiscoveryPacket.cpp +++ b/src/add-ons/kernel/network/ppp/pppoe/DiscoveryPacket.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2003-2004, Waldemar Kornewald + * Copyright 2003-2004, Waldemar Kornewald * Distributed under the terms of the MIT License. */ diff --git a/src/add-ons/kernel/network/ppp/pppoe/DiscoveryPacket.h b/src/add-ons/kernel/network/ppp/pppoe/DiscoveryPacket.h index 2e35337797..6c0416ffe0 100644 --- a/src/add-ons/kernel/network/ppp/pppoe/DiscoveryPacket.h +++ b/src/add-ons/kernel/network/ppp/pppoe/DiscoveryPacket.h @@ -1,5 +1,5 @@ /* - * Copyright 2003-2004, Waldemar Kornewald + * Copyright 2003-2004, Waldemar Kornewald * Distributed under the terms of the MIT License. */ diff --git a/src/add-ons/kernel/network/ppp/pppoe/PPPoE.h b/src/add-ons/kernel/network/ppp/pppoe/PPPoE.h index 9b128eb43e..6bb9350532 100644 --- a/src/add-ons/kernel/network/ppp/pppoe/PPPoE.h +++ b/src/add-ons/kernel/network/ppp/pppoe/PPPoE.h @@ -1,5 +1,5 @@ /* - * Copyright 2003-2004, Waldemar Kornewald + * Copyright 2003-2004, Waldemar Kornewald * Distributed under the terms of the MIT License. */ diff --git a/src/add-ons/kernel/network/ppp/pppoe/PPPoEDevice.cpp b/src/add-ons/kernel/network/ppp/pppoe/PPPoEDevice.cpp index 51bd1b4d23..1807d385e4 100644 --- a/src/add-ons/kernel/network/ppp/pppoe/PPPoEDevice.cpp +++ b/src/add-ons/kernel/network/ppp/pppoe/PPPoEDevice.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2003-2004, Waldemar Kornewald + * Copyright 2003-2004, Waldemar Kornewald * Distributed under the terms of the MIT License. */ diff --git a/src/add-ons/kernel/network/ppp/pppoe/PPPoEDevice.h b/src/add-ons/kernel/network/ppp/pppoe/PPPoEDevice.h index 86b4b040af..6fd9600d8c 100644 --- a/src/add-ons/kernel/network/ppp/pppoe/PPPoEDevice.h +++ b/src/add-ons/kernel/network/ppp/pppoe/PPPoEDevice.h @@ -1,5 +1,5 @@ /* - * Copyright 2003-2004, Waldemar Kornewald + * Copyright 2003-2004, Waldemar Kornewald * Distributed under the terms of the MIT License. */ diff --git a/src/add-ons/kernel/network/ppp/pppoe/pppoe.cpp b/src/add-ons/kernel/network/ppp/pppoe/pppoe.cpp index 7286be8231..81920d4a1d 100644 --- a/src/add-ons/kernel/network/ppp/pppoe/pppoe.cpp +++ b/src/add-ons/kernel/network/ppp/pppoe/pppoe.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2003-2004, Waldemar Kornewald + * Copyright 2003-2004, Waldemar Kornewald * Distributed under the terms of the MIT License. */ diff --git a/src/add-ons/kernel/network/ppp/shared/libkernelppp/Jamfile b/src/add-ons/kernel/network/ppp/shared/libkernelppp/Jamfile index 5995f6d984..c47f8534a6 100644 --- a/src/add-ons/kernel/network/ppp/shared/libkernelppp/Jamfile +++ b/src/add-ons/kernel/network/ppp/shared/libkernelppp/Jamfile @@ -22,7 +22,6 @@ R5KernelStaticLibrary kernelppp : KPPPLCP.cpp KPPPLCPExtension.cpp KPPPOptionHandler.cpp - KPPPProfile.cpp KPPPProtocol.cpp KPPPReportManager.cpp KPPPStateMachine.cpp diff --git a/src/add-ons/kernel/network/ppp/shared/libkernelppp/KPPPConfigurePacket.cpp b/src/add-ons/kernel/network/ppp/shared/libkernelppp/KPPPConfigurePacket.cpp index 223eda4485..f09a411dad 100644 --- a/src/add-ons/kernel/network/ppp/shared/libkernelppp/KPPPConfigurePacket.cpp +++ b/src/add-ons/kernel/network/ppp/shared/libkernelppp/KPPPConfigurePacket.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2003-2004, Waldemar Kornewald + * Copyright 2003-2004, Waldemar Kornewald * Distributed under the terms of the MIT License. */ diff --git a/src/add-ons/kernel/network/ppp/shared/libkernelppp/KPPPDevice.cpp b/src/add-ons/kernel/network/ppp/shared/libkernelppp/KPPPDevice.cpp index 137b65f00a..d40ee02477 100644 --- a/src/add-ons/kernel/network/ppp/shared/libkernelppp/KPPPDevice.cpp +++ b/src/add-ons/kernel/network/ppp/shared/libkernelppp/KPPPDevice.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2003-2004, Waldemar Kornewald + * Copyright 2003-2004, Waldemar Kornewald * Distributed under the terms of the MIT License. */ diff --git a/src/add-ons/kernel/network/ppp/shared/libkernelppp/KPPPInterface.cpp b/src/add-ons/kernel/network/ppp/shared/libkernelppp/KPPPInterface.cpp index 33adb6a334..9c342db37f 100644 --- a/src/add-ons/kernel/network/ppp/shared/libkernelppp/KPPPInterface.cpp +++ b/src/add-ons/kernel/network/ppp/shared/libkernelppp/KPPPInterface.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2003-2004, Waldemar Kornewald + * Copyright 2003-2005, Waldemar Kornewald * Distributed under the terms of the MIT License. */ @@ -66,8 +66,6 @@ status_t reconnect_thread(void *data); // other functions status_t interface_deleter_thread(void *data); -status_t call_open_event_thread(void *data); -status_t call_close_event_thread(void *data); /*! \brief Creates a new interface. @@ -76,23 +74,17 @@ status_t call_close_event_thread(void *data); \param entry The PPP manager passes an internal structure to the constructor. \param ID The interface's ID. \param settings (Optional): If no name is given you must pass the settings here. - \param profile (Optional): Overriding profile for this interface. \param parent (Optional): Interface's parent (only used for multilink interfaces). - - \sa KPPPProfile */ KPPPInterface::KPPPInterface(const char *name, ppp_interface_entry *entry, ppp_interface_id ID, const driver_settings *settings, - const driver_settings *profile, KPPPInterface *parent = NULL) + KPPPInterface *parent = NULL) : KPPPLayer(name, PPP_INTERFACE_LEVEL, 2), fID(ID), fSettings(NULL), fIfnet(NULL), - fUpThread(-1), - fOpenEventThread(-1), - fCloseEventThread(-1), fReconnectThread(-1), - fConnectRetry(0), + fConnectAttempt(1), fConnectRetriesLimit(0), fManager(NULL), fConnectedSince(0), @@ -104,6 +96,7 @@ KPPPInterface::KPPPInterface(const char *name, ppp_interface_entry *entry, fIsMultilink(false), fAutoReconnect(false), fConnectOnDemand(false), + fAskBeforeConnecting(false), fMode(PPP_CLIENT_MODE), fLocalPFCState(PPP_PFC_DISABLED), fPeerPFCState(PPP_PFC_DISABLED), @@ -112,7 +105,6 @@ KPPPInterface::KPPPInterface(const char *name, ppp_interface_entry *entry, fFirstProtocol(NULL), fStateMachine(*this), fLCP(*this), - fProfile(*this), fReportManager(StateMachine().fLock), fLock(StateMachine().fLock), fDeleteCounter(0) @@ -141,7 +133,6 @@ KPPPInterface::KPPPInterface(const char *name, ppp_interface_entry *entry, fInitStatus = B_ERROR; return; } - fProfile.LoadSettings(profile, fSettings); // add internal modules // LCP @@ -197,6 +188,12 @@ KPPPInterface::KPPPInterface(const char *name, ppp_interface_entry *entry, const char *value; + // get login + value = get_settings_value(PPP_USERNAME_KEY, fSettings); + fUsername = value ? strdup(value) : strdup(""); + value = get_settings_value(PPP_PASSWORD_KEY, fSettings); + fPassword = value ? strdup(value) : strdup(""); + // get DisonnectAfterIdleSince settings value = get_settings_value(PPP_DISONNECT_AFTER_IDLE_SINCE_KEY, fSettings); if(!value) @@ -222,6 +219,9 @@ KPPPInterface::KPPPInterface(const char *name, ppp_interface_entry *entry, ); // auto reconnect is disabled by default + fAskBeforeConnecting = get_boolean_value( + get_settings_value(PPP_ASK_BEFORE_CONNECTING_KEY, fSettings), false); + // load all protocols and the device if(!LoadModules(fSettings, 0, fSettings->parameter_count)) { ERROR("KPPPInterface: Error loading modules!\n"); @@ -265,8 +265,6 @@ KPPPInterface::~KPPPInterface() send_data_with_timeout(fReconnectThread, 0, NULL, 0, 200); // tell thread that we are being destroyed (200ms timeout) wait_for_thread(fReconnectThread, &tmp); - wait_for_thread(fOpenEventThread, &tmp); - wait_for_thread(fCloseEventThread, &tmp); while(CountChildren()) delete ChildAt(0); @@ -340,6 +338,30 @@ KPPPInterface::InitCheck() const } +//! The username used for authentication. +const char* +KPPPInterface::Username() const +{ + // this data is not available before we authenticate + if(Phase() < PPP_AUTHENTICATION_PHASE) + return NULL; + + return fUsername; +} + + +//! The password used for authentication. +const char* +KPPPInterface::Password() const +{ + // this data is not available before we authenticate + if(Phase() < PPP_AUTHENTICATION_PHASE) + return NULL; + + return fPassword; +} + + //! Sets interface MRU. bool KPPPInterface::SetMRU(uint32 MRU) @@ -383,6 +405,7 @@ KPPPInterface::PacketOverhead() const \return - \c B_OK: \c Control() was successful. - \c B_ERROR: Either \a length is too small or data is NULL. + - \c B_NOT_ALLOWED: Operation not allowed (at this point in time). - \c B_BAD_INDEX: Wrong index (e.g.: when accessing interface submodules). - \c B_BAD_VALUE: Unknown op. - Return value of submodule (when controlling one). @@ -419,7 +442,7 @@ KPPPInterface::Control(uint32 op, void *data, size_t length) info->childrenCount = CountChildren(); info->MRU = MRU(); info->interfaceMTU = InterfaceMTU(); - info->connectRetry = fConnectRetry; + info->connectAttempt = fConnectAttempt; info->connectRetriesLimit = fConnectRetriesLimit; info->connectRetryDelay = ConnectRetryDelay(); info->reconnectDelay = ReconnectDelay(); @@ -433,6 +456,46 @@ KPPPInterface::Control(uint32 op, void *data, size_t length) info->hasParent = Parent(); } break; + case PPPC_SET_USERNAME: { + if(!data) + return B_ERROR; + + LockerHelper locker(fLock); + // login information can only be changed before we authenticate + if(Phase() >= PPP_AUTHENTICATION_PHASE) + return B_NOT_ALLOWED; + + free(fUsername); + fUsername = data ? strdup((const char*) data) : strdup(""); + } break; + + case PPPC_SET_PASSWORD: { + if(!data) + return B_ERROR; + + LockerHelper locker(fLock); + // login information can only be changed before we authenticate + if(Phase() >= PPP_AUTHENTICATION_PHASE) + return B_NOT_ALLOWED; + + free(fPassword); + fPassword = data ? strdup((const char*) data) : strdup(""); + } break; + + case PPPC_SET_ASK_BEFORE_CONNECTING: + if(length < sizeof(uint32) || !data) + return B_ERROR; + + LockerHelper locker(fLock); + bool old = fAskBeforeConnecting; + fAskBeforeConnecting = *((uint32*)data); + if(old && fAskBeforeConnecting == false && State() == PPP_STARTING_STATE + && Phase() == PPP_DOWN_PHASE) { + locker.UnlockNow(); + StateMachine().ContinueOpenEvent(); + } + break; + case PPPC_SET_MRU: if(length < sizeof(uint32) || !data) return B_ERROR; @@ -468,7 +531,18 @@ KPPPInterface::Control(uint32 op, void *data, size_t length) if(length < sizeof(ppp_report_request) || !data) return B_ERROR; + LockerHelper locker(fLock); ppp_report_request *request = (ppp_report_request*) data; + // first, we send an initial state report + if(request->type == PPP_CONNECTION_REPORT) { + ppp_report_packet report; + report.type = PPP_CONNECTION_REPORT; + report.code = StateMachine().fLastConnectionReportCode; + report.length = sizeof(fID); + KPPPReportManager::SendReport(request->thread, &report); + if(request->flags & PPP_REMOVE_AFTER_REPORT) + return B_OK; + } ReportManager().EnableReports(request->type, request->thread, request->flags); } break; @@ -481,16 +555,6 @@ KPPPInterface::Control(uint32 op, void *data, size_t length) ReportManager().DisableReports(request->type, request->thread); } break; - case PPPC_SET_PROFILE: { - if(!data) - return B_ERROR; - - driver_settings *profile = (driver_settings*) data; - fProfile.LoadSettings(profile, fSettings); - - UpdateProfile(); - } break; - case PPPC_GET_STATISTICS: { if(length < sizeof(ppp_statistics) || !data) return B_ERROR; @@ -927,9 +991,9 @@ KPPPInterface::SetPFCOptions(uint8 pfcOptions) /*! \brief Brings this interface up. \c Down() overrides all \c Up() requests. \n - This blocks until the connection process is finished. + This method runs an asynchronous process (it returns immediately). - \return \c true if successful or \c false otherwise. + \return \c false on error. */ bool KPPPInterface::Up() @@ -942,173 +1006,24 @@ KPPPInterface::Up() if(IsUp()) return true; - ppp_report_packet report; - thread_id me = find_thread(NULL), sender; - - // One thread has to do the real task while all other threads are observers. // Lock needs timeout because destructor could have locked the interface. while(fLock.LockWithTimeout(100000) != B_NO_ERROR) if(fDeleteCounter > 0) return false; - if(fUpThread == -1) - fUpThread = me; - - ReportManager().EnableReports(PPP_CONNECTION_REPORT, me, PPP_WAIT_FOR_REPLY); - - // fUpThread/fReconnectThread tells the state machine to go up (using a new thread - // because we might not receive report messages otherwise) - if(me == fUpThread || me == fReconnectThread) { - if(fOpenEventThread != -1) { - int32 tmp; - wait_for_thread(fOpenEventThread, &tmp); - } - fOpenEventThread = spawn_kernel_thread(call_open_event_thread, - "KPPPInterface: call_open_event_thread", B_NORMAL_PRIORITY, this); - resume_thread(fOpenEventThread); - } + StateMachine().OpenEvent(); fLock.Unlock(); - if(me == fReconnectThread && me != fUpThread) - return true; - // the reconnect thread is doing a ConnectRetry in this case (fUpThread - // is waiting for new reports) - - while(true) { - // A wrong code usually happens when the reconnect thread gets notified - // of a Down() request. In that case a report will follow soon, so - // this can be ignored. - if(receive_data(&sender, &report, sizeof(report)) != PPP_REPORT_CODE) - continue; - -// TRACE("KPPPInterface::Up(): Report: Type = %ld Code = %ld\n", report.type, -// report.code); - - if(IsUp()) { - if(me == fUpThread) { - fConnectRetry = 0; - fUpThread = -1; - } - - PPP_REPLY(sender, PPP_OK_DISABLE_REPORTS); - return true; - } - - if(report.type == PPP_DESTRUCTION_REPORT) { - if(me == fUpThread) { - fConnectRetry = 0; - fUpThread = -1; - } - - PPP_REPLY(sender, PPP_OK_DISABLE_REPORTS); - return false; - } else if(report.type != PPP_CONNECTION_REPORT) { - PPP_REPLY(sender, B_OK); - continue; - } - - if(report.code == PPP_REPORT_GOING_UP) { - PPP_REPLY(sender, B_OK); - continue; - } else if(report.code == PPP_REPORT_UP_SUCCESSFUL) { - if(me == fUpThread) { - fConnectRetry = 0; - fUpThread = -1; - send_data_with_timeout(fReconnectThread, 0, NULL, 0, 200); - // notify reconnect thread that we do not need it anymore - } - - PPP_REPLY(sender, PPP_OK_DISABLE_REPORTS); - return true; - } else if(report.code == PPP_REPORT_DOWN_SUCCESSFUL - || report.code == PPP_REPORT_UP_ABORTED - || report.code == PPP_REPORT_LOCAL_AUTHENTICATION_FAILED - || report.code == PPP_REPORT_PEER_AUTHENTICATION_FAILED) { - if(me == fUpThread) { - fConnectRetry = 0; - fUpThread = -1; - - if(report.code != PPP_REPORT_DOWN_SUCCESSFUL) - Delete(); - } - - PPP_REPLY(sender, PPP_OK_DISABLE_REPORTS); - return false; - } - - if(me != fUpThread) { - // I am an observer - if(report.code == PPP_REPORT_DEVICE_UP_FAILED) { - if(fConnectRetry >= fConnectRetriesLimit || fUpThread == -1) { - PPP_REPLY(sender, PPP_OK_DISABLE_REPORTS); - return false; - } else { - PPP_REPLY(sender, B_OK); - continue; - } - } else if(report.code == PPP_REPORT_CONNECTION_LOST) { - if(DoesAutoReconnect()) { - PPP_REPLY(sender, B_OK); - continue; - } else { - PPP_REPLY(sender, PPP_OK_DISABLE_REPORTS); - return false; - } - } - } else { - // I am the thread for the real task - if(report.code == PPP_REPORT_DEVICE_UP_FAILED) { - if(fConnectRetry >= fConnectRetriesLimit) { - TRACE("KPPPInterface::Up(): DEVICE_UP_FAILED: >=maxretries!\n"); - - fConnectRetry = 0; - fUpThread = -1; - Delete(); - PPP_REPLY(sender, PPP_OK_DISABLE_REPORTS); - - return false; - } else { - TRACE("KPPPInterface::Up(): DEVICE_UP_FAILED: 0) + return false; ReportManager().EnableReports(PPP_CONNECTION_REPORT, find_thread(NULL)); + fLock.Unlock(); - thread_id sender; ppp_report_packet report; - - if(fCloseEventThread != -1) { - int32 tmp; - wait_for_thread(fCloseEventThread, &tmp); - } - - fCloseEventThread = spawn_kernel_thread(call_close_event_thread, - "KPPPInterface: call_close_event_thread", B_NORMAL_PRIORITY, this); - resume_thread(fCloseEventThread); - locker.UnlockNow(); - + thread_id sender; + bool successful = false; while(true) { if(receive_data(&sender, &report, sizeof(report)) != PPP_REPORT_CODE) continue; if(report.type == PPP_DESTRUCTION_REPORT) - return true; - - if(report.type != PPP_CONNECTION_REPORT) + break; + else if(report.type != PPP_CONNECTION_REPORT) continue; - if(report.code == PPP_REPORT_DOWN_SUCCESSFUL - || report.code == PPP_REPORT_UP_ABORTED - || (State() == PPP_INITIAL_STATE && Phase() == PPP_DOWN_PHASE)) { - ReportManager().DisableReports(PPP_CONNECTION_REPORT, find_thread(NULL)); + if(report.code == PPP_REPORT_UP_SUCCESSFUL) { + successful = true; + break; + } else if(report.code == PPP_REPORT_DOWN_SUCCESSFUL) break; - } } - Delete(); - return true; + ReportManager().DisableReports(PPP_CONNECTION_REPORT, find_thread(NULL)); + return successful; } @@ -1172,7 +1089,6 @@ bool KPPPInterface::IsUp() const { LockerHelper locker(fLock); - return Phase() == PPP_ESTABLISHED_PHASE; } @@ -1215,7 +1131,7 @@ KPPPInterface::LoadModules(driver_settings *settings, int32 start, int32 count) if(IsMultilink() && !Parent()) { // main interfaces only load the multilink module // and create a child using their settings - fManager->CreateInterface(settings, Profile().Settings(), ID()); + fManager->CreateInterface(settings, ID()); return true; } @@ -1322,11 +1238,11 @@ KPPPInterface::Send(struct mbuf *packet, uint16 protocolNumber) return B_ERROR; } - // go up if ConnectOnDemand enabled and we are down - if(protocolNumber != PPP_LCP_PROTOCOL && DoesConnectOnDemand() + // go up if ConnectOnDemand is enabled and we are disconnected + if((protocolNumber != PPP_LCP_PROTOCOL && DoesConnectOnDemand() && (Phase() == PPP_DOWN_PHASE || Phase() == PPP_ESTABLISHMENT_PHASE) - && !Up()) { + && !Up()) || !WaitForConnection()) { m_freem(packet); return B_ERROR; } @@ -1604,16 +1520,6 @@ KPPPInterface::UnregisterInterface() } -//! Called when profile changes. -void -KPPPInterface::UpdateProfile() -{ - KPPPLayer *layer = FirstProtocol(); - for(; layer; layer = layer->Next()) - layer->ProfileChanged(); -} - - //! Called by KPPPManager: manager routes stack ioctls to the corresponding interface. status_t KPPPInterface::StackControl(uint32 op, void *data) @@ -1741,14 +1647,16 @@ KPPPInterface::Reconnect(uint32 delay) if(fReconnectThread != -1) return; + ++fConnectAttempt; + // start a new thread that calls our Up() method reconnect_info info; info.interface = this; info.thread = &fReconnectThread; info.delay = delay; - fReconnectThread = spawn_kernel_thread(reconnect_thread, "KPPPInterface: reconnect_thread", - B_NORMAL_PRIORITY, NULL); + fReconnectThread = spawn_kernel_thread(reconnect_thread, + "KPPPInterface: reconnect_thread", B_NORMAL_PRIORITY, NULL); resume_thread(fReconnectThread); @@ -1768,9 +1676,6 @@ reconnect_thread(void *data) // we try to receive data instead of snooze, so we can quit on destruction if(receive_data_with_timeout(&sender, &code, NULL, 0, info.delay) == B_OK) { *info.thread = -1; - ppp_interface_id id = info.interface->ID(); - info.interface->Report(PPP_CONNECTION_REPORT, PPP_REPORT_UP_ABORTED, - &id, sizeof(ppp_interface_id)); return B_OK; } @@ -1791,24 +1696,6 @@ class KPPPInterfaceAccess { void Delete(KPPPInterface *interface) { delete interface; } - void CallOpenEvent(KPPPInterface *interface) - { - while(interface->fLock.LockWithTimeout(100000) != B_NO_ERROR) - if(interface->fDeleteCounter > 0) - return; - interface->CallOpenEvent(); - interface->fOpenEventThread = -1; - interface->fLock.Unlock(); - } - void CallCloseEvent(KPPPInterface *interface) - { - while(interface->fLock.LockWithTimeout(100000) != B_NO_ERROR) - if(interface->fDeleteCounter > 0) - return; - interface->CallCloseEvent(); - interface->fCloseEventThread = -1; - interface->fLock.Unlock(); - } }; @@ -1820,23 +1707,3 @@ interface_deleter_thread(void *data) return B_OK; } - - -status_t -call_open_event_thread(void *data) -{ - KPPPInterfaceAccess access; - access.CallOpenEvent((KPPPInterface*) data); - - return B_OK; -} - - -status_t -call_close_event_thread(void *data) -{ - KPPPInterfaceAccess access; - access.CallCloseEvent((KPPPInterface*) data); - - return B_OK; -} diff --git a/src/add-ons/kernel/network/ppp/shared/libkernelppp/KPPPLCP.cpp b/src/add-ons/kernel/network/ppp/shared/libkernelppp/KPPPLCP.cpp index 130ea47420..f967e68a3f 100644 --- a/src/add-ons/kernel/network/ppp/shared/libkernelppp/KPPPLCP.cpp +++ b/src/add-ons/kernel/network/ppp/shared/libkernelppp/KPPPLCP.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2003-2004, Waldemar Kornewald + * Copyright 2003-2005, Waldemar Kornewald * Distributed under the terms of the MIT License. */ @@ -221,27 +221,6 @@ KPPPLCP::AdditionalOverhead() const } -//! Calls \c ProfileChanged() for each option handler and LCP extension. -void -KPPPLCP::ProfileChanged() -{ - KPPPLCPExtension *extension; - KPPPOptionHandler *handler; - - for(int32 index = 0; index < CountLCPExtensions(); index++) { - extension = LCPExtensionAt(index); - if(extension) - extension->ProfileChanged(); - } - - for(int32 index = 0; index < CountOptionHandlers(); index++) { - handler = OptionHandlerAt(index); - if(handler) - handler->ProfileChanged(); - } -} - - //! Always returns \c true. bool KPPPLCP::Up() diff --git a/src/add-ons/kernel/network/ppp/shared/libkernelppp/KPPPLCPExtension.cpp b/src/add-ons/kernel/network/ppp/shared/libkernelppp/KPPPLCPExtension.cpp index 6e05013f3c..e5e5451d07 100644 --- a/src/add-ons/kernel/network/ppp/shared/libkernelppp/KPPPLCPExtension.cpp +++ b/src/add-ons/kernel/network/ppp/shared/libkernelppp/KPPPLCPExtension.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2003-2004, Waldemar Kornewald + * Copyright 2003-2005, Waldemar Kornewald * Distributed under the terms of the MIT License. */ @@ -99,19 +99,6 @@ KPPPLCPExtension::StackControl(uint32 op, void *data) } -/*! \brief Notification hook when the interface profile changes dynamically. - - You should override this method to update your profile settings if this extension - has such settings at all. This is mostly used by authenticators and possibly - protocols. -*/ -void -KPPPLCPExtension::ProfileChanged() -{ - // do nothing by default -} - - /*! \brief Reset internal connection state. This method is called when: connecting, reconfiguring, or disconnecting. diff --git a/src/add-ons/kernel/network/ppp/shared/libkernelppp/KPPPLayer.cpp b/src/add-ons/kernel/network/ppp/shared/libkernelppp/KPPPLayer.cpp index f929804feb..1a781c432c 100644 --- a/src/add-ons/kernel/network/ppp/shared/libkernelppp/KPPPLayer.cpp +++ b/src/add-ons/kernel/network/ppp/shared/libkernelppp/KPPPLayer.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2003-2004, Waldemar Kornewald + * Copyright 2003-2005, Waldemar Kornewald * Distributed under the terms of the MIT License. */ @@ -54,19 +54,6 @@ KPPPLayer::InitCheck() const } -/*! \brief Notification hook when the interface profile changes dynamically. - - You should override this method to update your profile settings if this layer - has such settings at all. This is mostly used by authenticators and possibly - protocols. -*/ -void -KPPPLayer::ProfileChanged() -{ - // do nothing by default -} - - //! Sends a packet to the next layer in the chain. status_t KPPPLayer::SendToNext(struct mbuf *packet, uint16 protocolNumber) const diff --git a/src/add-ons/kernel/network/ppp/shared/libkernelppp/KPPPOptionHandler.cpp b/src/add-ons/kernel/network/ppp/shared/libkernelppp/KPPPOptionHandler.cpp index d3d452e6e3..982d7c9f22 100644 --- a/src/add-ons/kernel/network/ppp/shared/libkernelppp/KPPPOptionHandler.cpp +++ b/src/add-ons/kernel/network/ppp/shared/libkernelppp/KPPPOptionHandler.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2003-2004, Waldemar Kornewald + * Copyright 2003-2005, Waldemar Kornewald * Distributed under the terms of the MIT License. */ @@ -99,19 +99,6 @@ KPPPOptionHandler::StackControl(uint32 op, void *data) } -/*! \brief Notification hook when the interface profile changes dynamically. - - You should override this method to update your profile settings if this handler - has such settings at all. This is mostly used by authenticators and possibly - protocols. -*/ -void -KPPPOptionHandler::ProfileChanged() -{ - // do nothing by default -} - - /*! \brief Add request item. What you do here depends on the connection side (client or server). \n diff --git a/src/add-ons/kernel/network/ppp/shared/libkernelppp/KPPPProfile.cpp b/src/add-ons/kernel/network/ppp/shared/libkernelppp/KPPPProfile.cpp deleted file mode 100644 index 01821befc4..0000000000 --- a/src/add-ons/kernel/network/ppp/shared/libkernelppp/KPPPProfile.cpp +++ /dev/null @@ -1,135 +0,0 @@ -/* - * Copyright 2003-2004, Waldemar Kornewald - * Distributed under the terms of the MIT License. - */ - -/*! \class KPPPProfile - \brief Manages profiles for KPPPInterface. - - PPP modules should store their user-specific and private settings in profiles. - This allows one interface description to be used by multiple users although - they have different logins. Temporary profiles are used when you enter a password - in the connection prompt. - PPP servers may use \c Request() to communicate with the userland PPP add-ons. - These add-ons could, for instance, forward all requests to a central server or - database. -*/ - -#include - -#include -#include "settings_tools.h" - - -//! Initializes profile. -KPPPProfile::KPPPProfile(KPPPInterface& interface) - : fInterface(interface), - fSettings(NULL) -{ -} - - -//! Frees profile settings. -KPPPProfile::~KPPPProfile() -{ - if(fSettings != Interface().Settings()) - free_driver_settings(fSettings); -} - - -/*! \brief Loads profile settings. - - Search order for profiles: - - given profile - - profile mentioned in interface settings ("profile $type { name $name }") - - profile description file with name of this interface - - the interface's settings (to stay compatible with the simple in-settings - description format) - - \param profile The dynamically created profile for this interface (if defined). - \param interfaceSettings The interface's settings. -*/ -void -KPPPProfile::LoadSettings(const driver_settings *profile, - driver_settings *interfaceSettings) -{ - if(fSettings != Interface().Settings()) - free_driver_settings(fSettings); - - // ----------------------------- - // given profile - // ----------------------------- - if(profile) { - fSettings = dup_driver_settings(profile); - return; - } - - // ----------------------------- - // profile in settings and - // profile with interface's name - // TODO: try /etc/ppp/profile if local profile could not be found - // ----------------------------- - const char *name = NULL; - char path[B_PATH_NAME_LENGTH]; - const driver_parameter *parameter = get_parameter_with_name("profile", - interfaceSettings); - - // TODO: add support for "ppp_server" profile type - if(parameter && parameter->value_count > 0 && parameter->parameter_count > 0 - && !strcasecmp(parameter->values[0], "file")) - name = get_parameter_value("name", parameter); - else if(Interface().Name()) - name = Interface().Name(); - - if(name) { - sprintf(path, "ptpnet/profile/%s", name); - void *handle = load_driver_settings(path); - if(handle) { - fSettings = dup_driver_settings(get_driver_settings(handle)); - unload_driver_settings(handle); - - if(fSettings) - return; - } - } - - // ----------------------------- - // interface's settings - // ----------------------------- - fSettings = interfaceSettings; -} - - -/*! \brief Finds a parameter for a module of type \a type and name \a name. - - This method is intended for modules. - - \param type Module's type (e.g.: "authenticator"). - \param name Module's name (e.g.: "pap"). - - \return - \c NULL: No parameter was found. -*/ -const driver_parameter* -KPPPProfile::SettingsFor(const char *type, const char *name) const -{ - if(!Settings() || !type) - return NULL; - - const driver_parameter *parameter; - for(int32 index = 0; index < Settings()->parameter_count; index++) { - parameter = &Settings()->parameters[index]; - - if(!strcasecmp(parameter->name, type)) { - if(name) { - for(int32 valueIndex = 0; valueIndex < parameter->value_count; - valueIndex++) - if(!strcasecmp(parameter->values[valueIndex], name)) - return parameter; - } else - return parameter; - } - } - - return NULL; -} diff --git a/src/add-ons/kernel/network/ppp/shared/libkernelppp/KPPPProtocol.cpp b/src/add-ons/kernel/network/ppp/shared/libkernelppp/KPPPProtocol.cpp index f7fc00d6db..7f6f712096 100644 --- a/src/add-ons/kernel/network/ppp/shared/libkernelppp/KPPPProtocol.cpp +++ b/src/add-ons/kernel/network/ppp/shared/libkernelppp/KPPPProtocol.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2003-2004, Waldemar Kornewald + * Copyright 2003-2004, Waldemar Kornewald * Distributed under the terms of the MIT License. */ diff --git a/src/add-ons/kernel/network/ppp/shared/libkernelppp/KPPPReportManager.cpp b/src/add-ons/kernel/network/ppp/shared/libkernelppp/KPPPReportManager.cpp index 9f0f31f3b9..eee82b3259 100644 --- a/src/add-ons/kernel/network/ppp/shared/libkernelppp/KPPPReportManager.cpp +++ b/src/add-ons/kernel/network/ppp/shared/libkernelppp/KPPPReportManager.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2003-2004, Waldemar Kornewald + * Copyright 2003-2005, Waldemar Kornewald * Distributed under the terms of the MIT License. */ @@ -8,11 +8,27 @@ */ #include -#include +#include #include +typedef struct report_sender_info { + thread_id thread; + ppp_report_packet report; +} report_sender_info; + + +static status_t +report_sender_thread(void *data) +{ + report_sender_info *info = static_cast(data); + KPPPReportManager::SendReport(info->thread, &info->report); + delete info; + return B_OK; +} + + /*! \brief Constructor. \param lock The BLocker that should be used by this report manager. @@ -31,6 +47,34 @@ KPPPReportManager::~KPPPReportManager() } +/*! \brief Send the given report message to the given thread. + + \param thread The report receiver. + \param report The report message. + + \return \c false on error. +*/ +bool +KPPPReportManager::SendReport(thread_id thread, const ppp_report_packet *report) +{ + if(!report) + return false; + + if(thread == find_thread(NULL)) { + report_sender_info *info = new report_sender_info; + info->thread = thread; + memcpy(&info->report, report, sizeof(ppp_report_packet)); + resume_thread(spawn_thread(report_sender_thread, "PPP: ReportSender", + B_NORMAL_PRIORITY, info)); + return true; + } + + send_data_with_timeout(thread, PPP_REPORT_CODE, &report, sizeof(report), + PPP_REPORT_TIMEOUT); + return true; +} + + /*! \brief Requests report messages of a given \a type. \param type The type of report. @@ -75,6 +119,12 @@ KPPPReportManager::DisableReports(ppp_report_type type, thread_id thread) if(request->type == type || type == PPP_ALL_REPORTS) fReportRequests.RemoveItem(request); } + + // empty message queue + while(has_data(thread)) { + thread_id sender; + receive_data(&sender, NULL, 0); + } } @@ -110,7 +160,7 @@ KPPPReportManager::DoesReport(ppp_report_type type, thread_id thread) \param data Additional data. \param length Length of the data. - \return \c true if all receivers accepted the message or \c false otherwise. + \return \c false on error. */ bool KPPPReportManager::Report(ppp_report_type type, int32 code, void *data, int32 length) @@ -130,8 +180,7 @@ KPPPReportManager::Report(ppp_report_type type, int32 code, void *data, int32 le LockerHelper locker(fLock); status_t result; - thread_id sender, me = find_thread(NULL); - bool acceptable = true; + thread_id me = find_thread(NULL); ppp_report_packet report; report.type = type; @@ -156,63 +205,13 @@ KPPPReportManager::Report(ppp_report_type type, int32 code, void *data, int32 le TRACE("KPPPReportManager::Report(): timed out sending\n"); #endif - thread_info info; - - if(result == B_BAD_THREAD_ID || result == B_NO_MEMORY) { + if(result == B_BAD_THREAD_ID || result == B_NO_MEMORY + || request->flags & PPP_REMOVE_AFTER_REPORT) { fReportRequests.RemoveItem(request); --index; continue; - } else if(result == B_OK && request->flags & PPP_WAIT_FOR_REPLY) { - if(request->flags & PPP_NO_REPLY_TIMEOUT) { - sender = -1; - result = B_ERROR; - // always check if the thread still exists - while(sender != request->thread - && get_thread_info(request->thread, &info) == B_OK) { - result = receive_data_with_timeout(&sender, &code, NULL, 0, - PPP_REPORT_TIMEOUT); - - if(request->flags & PPP_ALLOW_ANY_REPLY_THREAD - && result == B_OK) - sender = request->thread; - } - } else { - sender = -1; - result = B_OK; - while(sender != request->thread && result == B_OK - && get_thread_info(request->thread, &info) == B_OK) { - result = receive_data_with_timeout(&sender, &code, NULL, 0, - PPP_REPORT_TIMEOUT); - - if(request->flags & PPP_ALLOW_ANY_REPLY_THREAD) - sender = request->thread; - } - } - - if(sender != request->thread) { - TRACE("KPPPReportManager::Report(): sender != requested\n"); - continue; - } - - if(result == B_OK && code != B_OK && code != PPP_OK_DISABLE_REPORTS) - acceptable = false; - -#if DEBUG - if(result == B_TIMED_OUT) - TRACE("KPPPReportManager::Report(): reply timed out\n"); -#endif - } - - // remove thread if it is not existant or if remove-flag is set - if(request->flags & PPP_REMOVE_AFTER_REPORT - || get_thread_info(request->thread, &info) != B_OK - || code == PPP_OK_DISABLE_REPORTS) { - fReportRequests.RemoveItem(request); - --index; } } - TRACE("KPPPReportManager::Report(): returning: %s\n", acceptable?"true":"false"); - - return acceptable; + return true; } diff --git a/src/add-ons/kernel/network/ppp/shared/libkernelppp/KPPPStateMachine.cpp b/src/add-ons/kernel/network/ppp/shared/libkernelppp/KPPPStateMachine.cpp index 41409ad500..00d0b7326e 100644 --- a/src/add-ons/kernel/network/ppp/shared/libkernelppp/KPPPStateMachine.cpp +++ b/src/add-ons/kernel/network/ppp/shared/libkernelppp/KPPPStateMachine.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2003-2004, Waldemar Kornewald + * Copyright 2003-2005, Waldemar Kornewald * Distributed under the terms of the MIT License. */ @@ -20,6 +20,7 @@ #include #include +#include #include #include @@ -37,6 +38,7 @@ KPPPStateMachine::KPPPStateMachine(KPPPInterface& interface) fPhase(PPP_DOWN_PHASE), fID(system_time() & 0xFF), fMagicNumber(0), + fLastConnectionReportCode(PPP_REPORT_DOWN_SUCCESSFUL), fLocalAuthenticationStatus(PPP_NOT_AUTHENTICATED), fPeerAuthenticationStatus(PPP_NOT_AUTHENTICATED), fLocalAuthenticationName(NULL), @@ -129,6 +131,11 @@ KPPPStateMachine::NewPhase(ppp_phase next) if(Interface().Ifnet()) Interface().Ifnet()->if_flags |= IFF_UP | IFF_RUNNING; + Interface().fConnectAttempt = 0; + // when we Reconnect() this becomes 1 (the first connection attempt) + send_data_with_timeout(Interface().fReconnectThread, 0, NULL, 0, 200); + // abort possible reconnect attempt + fLastConnectionReportCode = PPP_REPORT_UP_SUCCESSFUL; Interface().Report(PPP_CONNECTION_REPORT, PPP_REPORT_UP_SUCCESSFUL, &fInterface.fID, sizeof(ppp_interface_id)); } @@ -230,8 +237,9 @@ KPPPStateMachine::LocalAuthenticationRequested() LockerHelper locker(fLock); + fLastConnectionReportCode = PPP_REPORT_AUTHENTICATION_REQUESTED; Interface().Report(PPP_CONNECTION_REPORT, - PPP_REPORT_LOCAL_AUTHENTICATION_REQUESTED, &fInterface.fID, + PPP_REPORT_AUTHENTICATION_REQUESTED, &fInterface.fID, sizeof(ppp_interface_id)); fLocalAuthenticationStatus = PPP_AUTHENTICATING; @@ -260,10 +268,6 @@ KPPPStateMachine::LocalAuthenticationAccepted(const char *name) fLocalAuthenticationName = strdup(name); else fLocalAuthenticationName = NULL; - - Interface().Report(PPP_CONNECTION_REPORT, - PPP_REPORT_LOCAL_AUTHENTICATION_SUCCESSFUL, &fInterface.fID, - sizeof(ppp_interface_id)); } @@ -300,8 +304,9 @@ KPPPStateMachine::PeerAuthenticationRequested() LockerHelper locker(fLock); + fLastConnectionReportCode = PPP_REPORT_AUTHENTICATION_REQUESTED; Interface().Report(PPP_CONNECTION_REPORT, - PPP_REPORT_PEER_AUTHENTICATION_REQUESTED, &fInterface.fID, + PPP_REPORT_AUTHENTICATION_REQUESTED, &fInterface.fID, sizeof(ppp_interface_id)); fPeerAuthenticationStatus = PPP_AUTHENTICATING; @@ -330,10 +335,6 @@ KPPPStateMachine::PeerAuthenticationAccepted(const char *name) fPeerAuthenticationName = strdup(name); else fPeerAuthenticationName = NULL; - - Interface().Report(PPP_CONNECTION_REPORT, - PPP_REPORT_PEER_AUTHENTICATION_SUCCESSFUL, &fInterface.fID, - sizeof(ppp_interface_id)); } @@ -560,6 +561,7 @@ KPPPStateMachine::UpFailedEvent() switch(State()) { case PPP_STARTING_STATE: + fLastConnectionReportCode = PPP_REPORT_DEVICE_UP_FAILED; Interface().Report(PPP_CONNECTION_REPORT, PPP_REPORT_DEVICE_UP_FAILED, &fInterface.fID, sizeof(ppp_interface_id)); if(Interface().Parent()) @@ -696,29 +698,32 @@ KPPPStateMachine::DownEvent() // maybe we need to reconnect if(State() == PPP_STARTING_STATE) { - bool needsReconnect = false; + bool deleteInterface = false, retry = false; // we do not try to reconnect if authentication failed if(fLocalAuthenticationStatus == PPP_AUTHENTICATION_FAILED - || fLocalAuthenticationStatus == PPP_AUTHENTICATING) + || fLocalAuthenticationStatus == PPP_AUTHENTICATING + || fPeerAuthenticationStatus == PPP_AUTHENTICATION_FAILED + || fPeerAuthenticationStatus == PPP_AUTHENTICATING) { + fLastConnectionReportCode = PPP_REPORT_AUTHENTICATION_FAILED; Interface().Report(PPP_CONNECTION_REPORT, - PPP_REPORT_LOCAL_AUTHENTICATION_FAILED, &fInterface.fID, + PPP_REPORT_AUTHENTICATION_FAILED, &fInterface.fID, sizeof(ppp_interface_id)); - else if(fPeerAuthenticationStatus == PPP_AUTHENTICATION_FAILED - || fPeerAuthenticationStatus == PPP_AUTHENTICATING) - Interface().Report(PPP_CONNECTION_REPORT, - PPP_REPORT_PEER_AUTHENTICATION_FAILED, &fInterface.fID, - sizeof(ppp_interface_id)); - else { - // if we are going up and lost connection the reconnect attempt becomes - // a connect retry which is managed by the main thread in Interface::Up() - if(Interface().fUpThread == -1) - needsReconnect = true; + deleteInterface = true; + } else { + if(Interface().fConnectAttempt > (Interface().fConnectRetriesLimit + 1)) + deleteInterface = true; - // test if UpFailedEvent() was not called - if(oldPhase != PPP_DOWN_PHASE) + if(oldPhase == PPP_DOWN_PHASE) { + // failed to bring device up (UpFailedEvent() was called) + retry = true; + // this may have been overridden by "deleteInterface = true" + } else { + // lost connection (TLFNotify() was called) + fLastConnectionReportCode = PPP_REPORT_CONNECTION_LOST; Interface().Report(PPP_CONNECTION_REPORT, PPP_REPORT_CONNECTION_LOST, &fInterface.fID, sizeof(ppp_interface_id)); + } } if(Interface().Parent()) @@ -726,15 +731,14 @@ KPPPStateMachine::DownEvent() NewState(PPP_INITIAL_STATE); - if(Interface().DoesAutoReconnect()) { - if(needsReconnect) - Interface().Reconnect(Interface().ReconnectDelay()); - } else + if(!deleteInterface && (retry || Interface().DoesAutoReconnect())) + Interface().Reconnect(Interface().ReconnectDelay()); + else Interface().Delete(); } else { + fLastConnectionReportCode = PPP_REPORT_DOWN_SUCCESSFUL; Interface().Report(PPP_CONNECTION_REPORT, PPP_REPORT_DOWN_SUCCESSFUL, &fInterface.fID, sizeof(ppp_interface_id)); - Interface().Delete(); } @@ -759,9 +763,9 @@ KPPPStateMachine::OpenEvent() switch(State()) { case PPP_INITIAL_STATE: - if(!Interface().Report(PPP_CONNECTION_REPORT, PPP_REPORT_GOING_UP, - &fInterface.fID, sizeof(ppp_interface_id))) - return; + fLastConnectionReportCode = PPP_REPORT_GOING_UP; + Interface().Report(PPP_CONNECTION_REPORT, PPP_REPORT_GOING_UP, + &fInterface.fID, sizeof(ppp_interface_id)) if(Interface().Mode() == PPP_SERVER_MODE) { NewPhase(PPP_ESTABLISHMENT_PHASE); @@ -773,14 +777,9 @@ KPPPStateMachine::OpenEvent() } else NewState(PPP_STARTING_STATE); - if(Interface().IsMultilink() && !Interface().Parent()) { - NewPhase(PPP_ESTABLISHMENT_PHASE); - for(int32 index = 0; index < Interface().CountChildren(); index++) - if(Interface().ChildAt(index)->Mode() == Interface().Mode()) - Interface().ChildAt(index)->StateMachine().OpenEvent(); - } else { + if(Interface().fAskBeforeConnecting == false) { locker.UnlockNow(); - ThisLayerStarted(); + ContinueOpenEvent(); } break; @@ -807,6 +806,22 @@ KPPPStateMachine::OpenEvent() } +void +KPPPStateMachine::ContinueOpenEvent() +{ + TRACE("KPPPSM: ContinueOpenEvent() state=%d phase=%d\n", State(), Phase()); + + if(Interface().IsMultilink() && !Interface().Parent()) { + LockerHelper locker(fLock); + NewPhase(PPP_ESTABLISHMENT_PHASE); + for(int32 index = 0; index < Interface().CountChildren(); index++) + if(Interface().ChildAt(index)->Mode() == Interface().Mode()) + Interface().ChildAt(index)->StateMachine().OpenEvent(); + } else + ThisLayerStarted(); +} + + void KPPPStateMachine::CloseEvent() { @@ -1560,12 +1575,12 @@ KPPPStateMachine::RCREvent(struct mbuf *packet) } } - if(nak.CountItems() > 0) { - RCRBadEvent(nak.ToMbuf(Interface().MRU(), LCP().AdditionalOverhead()), NULL); - m_freem(packet); - } else if(reject.CountItems() > 0) { + if(reject.CountItems() > 0) { RCRBadEvent(NULL, reject.ToMbuf(Interface().MRU(), LCP().AdditionalOverhead())); m_freem(packet); + } else if(nak.CountItems() > 0) { + RCRBadEvent(nak.ToMbuf(Interface().MRU(), LCP().AdditionalOverhead()), NULL); + m_freem(packet); } else RCRGoodEvent(packet); } diff --git a/src/add-ons/kernel/network/ppp/shared/libkernelppp/KPPPUtils.cpp b/src/add-ons/kernel/network/ppp/shared/libkernelppp/KPPPUtils.cpp index 29f0779499..beddc13df3 100644 --- a/src/add-ons/kernel/network/ppp/shared/libkernelppp/KPPPUtils.cpp +++ b/src/add-ons/kernel/network/ppp/shared/libkernelppp/KPPPUtils.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2003-2004, Waldemar Kornewald + * Copyright 2003-2005, Waldemar Kornewald * Distributed under the terms of the MIT License. */ @@ -48,8 +48,9 @@ status_t receive_data_with_timeout(thread_id *sender, int32 *code, void *buffer, size_t buffer_size, uint32 timeout) { + thread_id me = find_thread(NULL); for(uint32 tries = 0; tries < timeout; tries += 5) { - if(!has_data(find_thread(NULL))) + if(!has_data(me)) snooze(5000); else break; diff --git a/src/add-ons/kernel/network/ppp/shared/libkernelppp/TODO b/src/add-ons/kernel/network/ppp/shared/libkernelppp/TODO index 382b9be52d..a821855ba5 100644 --- a/src/add-ons/kernel/network/ppp/shared/libkernelppp/TODO +++ b/src/add-ons/kernel/network/ppp/shared/libkernelppp/TODO @@ -1,4 +1,3 @@ - remove atomic.S when Haiku is finished - add missing settings support (ConnectRetryDelay, etc.) -- finish support for server mode (profiles, etc.) -- add callback support +- finish support for server mode diff --git a/src/add-ons/kernel/network/ppp/shared/libkernelppp/_KPPPAuthenticationHandler.cpp b/src/add-ons/kernel/network/ppp/shared/libkernelppp/_KPPPAuthenticationHandler.cpp index 4cdf0069c1..289ef9370b 100644 --- a/src/add-ons/kernel/network/ppp/shared/libkernelppp/_KPPPAuthenticationHandler.cpp +++ b/src/add-ons/kernel/network/ppp/shared/libkernelppp/_KPPPAuthenticationHandler.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2003-2004, Waldemar Kornewald + * Copyright 2003-2004, Waldemar Kornewald * Distributed under the terms of the MIT License. */ diff --git a/src/add-ons/kernel/network/ppp/shared/libkernelppp/_KPPPAuthenticationHandler.h b/src/add-ons/kernel/network/ppp/shared/libkernelppp/_KPPPAuthenticationHandler.h index d18332b017..ad68c43fe5 100644 --- a/src/add-ons/kernel/network/ppp/shared/libkernelppp/_KPPPAuthenticationHandler.h +++ b/src/add-ons/kernel/network/ppp/shared/libkernelppp/_KPPPAuthenticationHandler.h @@ -1,5 +1,5 @@ /* - * Copyright 2003-2004, Waldemar Kornewald + * Copyright 2003-2004, Waldemar Kornewald * Distributed under the terms of the MIT License. */ diff --git a/src/add-ons/kernel/network/ppp/shared/libkernelppp/_KPPPMRUHandler.cpp b/src/add-ons/kernel/network/ppp/shared/libkernelppp/_KPPPMRUHandler.cpp index a5da705bf1..8660f28b8a 100644 --- a/src/add-ons/kernel/network/ppp/shared/libkernelppp/_KPPPMRUHandler.cpp +++ b/src/add-ons/kernel/network/ppp/shared/libkernelppp/_KPPPMRUHandler.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2003-2004, Waldemar Kornewald + * Copyright 2003-2004, Waldemar Kornewald * Distributed under the terms of the MIT License. */ diff --git a/src/add-ons/kernel/network/ppp/shared/libkernelppp/_KPPPMRUHandler.h b/src/add-ons/kernel/network/ppp/shared/libkernelppp/_KPPPMRUHandler.h index 21c81d49cb..90ab77e016 100644 --- a/src/add-ons/kernel/network/ppp/shared/libkernelppp/_KPPPMRUHandler.h +++ b/src/add-ons/kernel/network/ppp/shared/libkernelppp/_KPPPMRUHandler.h @@ -1,5 +1,5 @@ /* - * Copyright 2003-2004, Waldemar Kornewald + * Copyright 2003-2004, Waldemar Kornewald * Distributed under the terms of the MIT License. */ diff --git a/src/add-ons/kernel/network/ppp/shared/libkernelppp/_KPPPPFCHandler.cpp b/src/add-ons/kernel/network/ppp/shared/libkernelppp/_KPPPPFCHandler.cpp index e430ef8972..c179979394 100644 --- a/src/add-ons/kernel/network/ppp/shared/libkernelppp/_KPPPPFCHandler.cpp +++ b/src/add-ons/kernel/network/ppp/shared/libkernelppp/_KPPPPFCHandler.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2003-2004, Waldemar Kornewald + * Copyright 2003-2004, Waldemar Kornewald * Distributed under the terms of the MIT License. */ diff --git a/src/add-ons/kernel/network/ppp/shared/libkernelppp/_KPPPPFCHandler.h b/src/add-ons/kernel/network/ppp/shared/libkernelppp/_KPPPPFCHandler.h index 7176b45eab..99b2b40022 100644 --- a/src/add-ons/kernel/network/ppp/shared/libkernelppp/_KPPPPFCHandler.h +++ b/src/add-ons/kernel/network/ppp/shared/libkernelppp/_KPPPPFCHandler.h @@ -1,5 +1,5 @@ /* - * Copyright 2003-2004, Waldemar Kornewald + * Copyright 2003-2004, Waldemar Kornewald * Distributed under the terms of the MIT License. */ diff --git a/src/add-ons/kernel/network/ppp/shared/libkernelppp/headers/KPPPInterface.h b/src/add-ons/kernel/network/ppp/shared/libkernelppp/headers/KPPPInterface.h index 9ef1e4b9a1..d7cf7730b3 100644 --- a/src/add-ons/kernel/network/ppp/shared/libkernelppp/headers/KPPPInterface.h +++ b/src/add-ons/kernel/network/ppp/shared/libkernelppp/headers/KPPPInterface.h @@ -1,5 +1,5 @@ /* - * Copyright 2003-2004, Haiku Inc. + * Copyright 2003-2005, Haiku Inc. * Distributed under the terms of the MIT License. */ @@ -20,10 +20,6 @@ #include #endif -#ifndef _K_PPP_PROFILE__H -#include -#endif - #ifndef _K_PPP_REPORT_MANAGER__H #include #endif @@ -56,7 +52,7 @@ class KPPPInterface : public KPPPLayer { // only PPPManager may construct us! KPPPInterface(const char *name, ppp_interface_entry *entry, ppp_interface_id ID, const driver_settings *settings, - const driver_settings *profile, KPPPInterface *parent = NULL); + KPPPInterface *parent = NULL); ~KPPPInterface(); public: @@ -78,14 +74,14 @@ class KPPPInterface : public KPPPLayer { //! Returns the KPPPLCP protocol of this interface. KPPPLCP& LCP() { return fLCP; } - //! Returns interface's profile object. - KPPPProfile& Profile() - { return fProfile; } //! Returns the interfac's ifnet structure that is exported to the netstack. struct ifnet *Ifnet() const { return fIfnet; } + const char *Username() const; + const char *Password() const; + //! Delay in miliseconds between a connect retry. uint32 ConnectRetryDelay() const { return fConnectRetryDelay; } @@ -199,6 +195,7 @@ class KPPPInterface : public KPPPLayer { virtual bool Up(); // in server mode Up() listens for an incoming connection virtual bool Down(); + bool WaitForConnection(); bool IsUp() const; //! Returns interface's report manager. @@ -233,8 +230,6 @@ class KPPPInterface : public KPPPLayer { // saves the returned ifnet structure bool UnregisterInterface(); - void UpdateProfile(); - status_t StackControl(uint32 op, void *data); // stack routes ioctls to interface status_t StackControlEachHandler(uint32 op, void *data); @@ -243,12 +238,6 @@ class KPPPInterface : public KPPPLayer { void CalculateInterfaceMTU(); void CalculateBaudRate(); - // these two methods are used by the open/close_event_threads - void CallOpenEvent() - { StateMachine().OpenEvent(); } - void CallCloseEvent() - { StateMachine().CloseEvent(); } - void Reconnect(uint32 delay); // multilink methods @@ -262,10 +251,10 @@ class KPPPInterface : public KPPPLayer { driver_settings *fSettings; struct ifnet *fIfnet; - thread_id fUpThread, fOpenEventThread, fCloseEventThread; + char *fUsername, *fPassword; thread_id fReconnectThread; - uint32 fConnectRetry, fConnectRetriesLimit; + uint32 fConnectAttempt, fConnectRetriesLimit; uint32 fConnectRetryDelay, fReconnectDelay; ppp_interface_module_info *fManager; @@ -280,7 +269,7 @@ class KPPPInterface : public KPPPLayer { TemplateList fChildren; bool fIsMultilink; - bool fAutoReconnect, fConnectOnDemand; + bool fAutoReconnect, fConnectOnDemand, fAskBeforeConnecting; ppp_mode fMode; ppp_pfc_state fLocalPFCState, fPeerPFCState; @@ -292,7 +281,6 @@ class KPPPInterface : public KPPPLayer { KPPPStateMachine fStateMachine; KPPPLCP fLCP; - KPPPProfile fProfile; KPPPReportManager fReportManager; BLocker& fLock; int32 fDeleteCounter; diff --git a/src/add-ons/kernel/network/ppp/shared/libkernelppp/headers/KPPPLCP.h b/src/add-ons/kernel/network/ppp/shared/libkernelppp/headers/KPPPLCP.h index c8f55b53af..5919911ddd 100644 --- a/src/add-ons/kernel/network/ppp/shared/libkernelppp/headers/KPPPLCP.h +++ b/src/add-ons/kernel/network/ppp/shared/libkernelppp/headers/KPPPLCP.h @@ -1,5 +1,5 @@ /* - * Copyright 2003-2004, Haiku Inc. + * Copyright 2003-2005, Haiku Inc. * Distributed under the terms of the MIT License. */ @@ -82,8 +82,6 @@ class KPPPLCP : public KPPPProtocol { uint32 AdditionalOverhead() const; // the overhead caused by the target, the device, and the interface - virtual void ProfileChanged(); - virtual bool Up(); virtual bool Down(); diff --git a/src/add-ons/kernel/network/ppp/shared/libkernelppp/headers/KPPPLCPExtension.h b/src/add-ons/kernel/network/ppp/shared/libkernelppp/headers/KPPPLCPExtension.h index 96a527ff6b..8d21c7b180 100644 --- a/src/add-ons/kernel/network/ppp/shared/libkernelppp/headers/KPPPLCPExtension.h +++ b/src/add-ons/kernel/network/ppp/shared/libkernelppp/headers/KPPPLCPExtension.h @@ -1,5 +1,5 @@ /* - * Copyright 2003-2004, Haiku Inc. + * Copyright 2003-2005, Haiku Inc. * Distributed under the terms of the MIT License. */ @@ -50,8 +50,6 @@ class KPPPLCPExtension { virtual status_t StackControl(uint32 op, void *data); // called by netstack (forwarded by KPPPInterface) - virtual void ProfileChanged(); - //! Must be overridden. Called when an LCP packet with your code is received. virtual status_t Receive(struct mbuf *packet, uint8 code) = 0; diff --git a/src/add-ons/kernel/network/ppp/shared/libkernelppp/headers/KPPPLayer.h b/src/add-ons/kernel/network/ppp/shared/libkernelppp/headers/KPPPLayer.h index c91f4c38b5..4aba95d118 100644 --- a/src/add-ons/kernel/network/ppp/shared/libkernelppp/headers/KPPPLayer.h +++ b/src/add-ons/kernel/network/ppp/shared/libkernelppp/headers/KPPPLayer.h @@ -1,5 +1,5 @@ /* - * Copyright 2003-2004, Haiku Inc. + * Copyright 2003-2005, Haiku Inc. * Distributed under the terms of the MIT License. */ @@ -39,8 +39,6 @@ class KPPPLayer { KPPPLayer *Next() const { return fNext; } - virtual void ProfileChanged(); - //! Brings this layer up. virtual bool Up() = 0; //! Brings this layer down. diff --git a/src/add-ons/kernel/network/ppp/shared/libkernelppp/headers/KPPPManager.h b/src/add-ons/kernel/network/ppp/shared/libkernelppp/headers/KPPPManager.h index a9e37feef5..eab3aa4204 100644 --- a/src/add-ons/kernel/network/ppp/shared/libkernelppp/headers/KPPPManager.h +++ b/src/add-ons/kernel/network/ppp/shared/libkernelppp/headers/KPPPManager.h @@ -1,5 +1,5 @@ /* - * Copyright 2003-2004, Haiku Inc. + * Copyright 2003-2005, Haiku Inc. * Distributed under the terms of the MIT License. */ @@ -24,9 +24,6 @@ typedef struct ppp_interface_entry { KPPPInterface *interface; vint32 accessing; bool deleting; - - // ppp_up communication - thread_id requestThread; } ppp_interface_entry; @@ -41,10 +38,8 @@ typedef struct ppp_interface_module_info { //!< Exports needed network module functions. ppp_interface_id (*CreateInterface)(const driver_settings *settings, - const driver_settings *profile = NULL, ppp_interface_id parentID = PPP_UNDEFINED_INTERFACE_ID); ppp_interface_id (*CreateInterfaceWithName)(const char *name, - const driver_settings *profile = NULL, ppp_interface_id parentID = PPP_UNDEFINED_INTERFACE_ID); bool (*DeleteInterface)(ppp_interface_id ID); // this marks the interface for deletion diff --git a/src/add-ons/kernel/network/ppp/shared/libkernelppp/headers/KPPPOptionHandler.h b/src/add-ons/kernel/network/ppp/shared/libkernelppp/headers/KPPPOptionHandler.h index 74128c64be..ac29aebfb9 100644 --- a/src/add-ons/kernel/network/ppp/shared/libkernelppp/headers/KPPPOptionHandler.h +++ b/src/add-ons/kernel/network/ppp/shared/libkernelppp/headers/KPPPOptionHandler.h @@ -1,5 +1,5 @@ /* - * Copyright 2003-2004, Haiku Inc. + * Copyright 2003-2005, Haiku Inc. * Distributed under the terms of the MIT License. */ @@ -52,8 +52,6 @@ class KPPPOptionHandler { virtual status_t StackControl(uint32 op, void *data); // called by netstack (forwarded by KPPPInterface) - virtual void ProfileChanged(); - // we want to send a configure request or we received a reply virtual status_t AddToRequest(KPPPConfigurePacket& request); virtual status_t ParseNak(const KPPPConfigurePacket& nak); diff --git a/src/add-ons/kernel/network/ppp/shared/libkernelppp/headers/KPPPProfile.h b/src/add-ons/kernel/network/ppp/shared/libkernelppp/headers/KPPPProfile.h deleted file mode 100644 index 2f4c3e7736..0000000000 --- a/src/add-ons/kernel/network/ppp/shared/libkernelppp/headers/KPPPProfile.h +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Copyright 2003-2004, Haiku Inc. - * Distributed under the terms of the MIT License. - */ - -#ifndef _K_PPP_PROFILE__H -#define _K_PPP_PROFILE__H - -#include - -class KPPPInterface; - - -class KPPPProfile { - friend class KPPPInterface; - - private: - KPPPProfile(KPPPInterface& interface); - ~KPPPProfile(); - void LoadSettings(const driver_settings *profile, - driver_settings *interfaceSettings); - - public: - //! Returns interface that owns this profile. - KPPPInterface& Interface() const - { return fInterface; } - //! Returns the loaded profile settings. - const driver_settings *Settings() const - { return fSettings; } - const driver_parameter *SettingsFor(const char *type, const char *name) const; - // name may be NULL - -// size_t Request(void *out, size_t outSize, void *in, size_t inSize) const; - - private: - KPPPInterface& fInterface; - driver_settings *fSettings; -}; - - -#endif diff --git a/src/add-ons/kernel/network/ppp/shared/libkernelppp/headers/KPPPReportManager.h b/src/add-ons/kernel/network/ppp/shared/libkernelppp/headers/KPPPReportManager.h index 072fc6c0f8..1d5f1eac63 100644 --- a/src/add-ons/kernel/network/ppp/shared/libkernelppp/headers/KPPPReportManager.h +++ b/src/add-ons/kernel/network/ppp/shared/libkernelppp/headers/KPPPReportManager.h @@ -1,5 +1,5 @@ /* - * Copyright 2003-2004, Haiku Inc. + * Copyright 2003-2005, Haiku Inc. * Distributed under the terms of the MIT License. */ @@ -19,6 +19,9 @@ class KPPPReportManager { KPPPReportManager(BLocker& lock); ~KPPPReportManager(); + static bool SendReport(thread_id thread, const ppp_report_packet *report); + // returns false if reply was bad (or an error occured) + void EnableReports(ppp_report_type type, thread_id thread, int32 flags = PPP_NO_FLAGS); void DisableReports(ppp_report_type type, thread_id thread); diff --git a/src/add-ons/kernel/network/ppp/shared/libkernelppp/headers/KPPPStateMachine.h b/src/add-ons/kernel/network/ppp/shared/libkernelppp/headers/KPPPStateMachine.h index 4c3d3532bf..07d2f5d6e3 100644 --- a/src/add-ons/kernel/network/ppp/shared/libkernelppp/headers/KPPPStateMachine.h +++ b/src/add-ons/kernel/network/ppp/shared/libkernelppp/headers/KPPPStateMachine.h @@ -159,6 +159,7 @@ class KPPPStateMachine { vint32 fID; uint32 fMagicNumber; + int32 fLastConnectionReportCode; ppp_authentication_status fLocalAuthenticationStatus, fPeerAuthenticationStatus; diff --git a/src/add-ons/kernel/network/ppp/shared/libkernelppp/headers/LockerHelper.h b/src/add-ons/kernel/network/ppp/shared/libkernelppp/headers/LockerHelper.h index e8ae588691..ac58ab5ac0 100644 --- a/src/add-ons/kernel/network/ppp/shared/libkernelppp/headers/LockerHelper.h +++ b/src/add-ons/kernel/network/ppp/shared/libkernelppp/headers/LockerHelper.h @@ -1,5 +1,5 @@ /* - * Copyright 2003-2004, Waldemar Kornewald + * Copyright 2003-2004, Waldemar Kornewald * Distributed under the terms of the MIT License. */ diff --git a/src/add-ons/kernel/network/ppp/shared/libkernelppp/headers/PPPControl.h b/src/add-ons/kernel/network/ppp/shared/libkernelppp/headers/PPPControl.h index 504a321af9..cb731571c7 100644 --- a/src/add-ons/kernel/network/ppp/shared/libkernelppp/headers/PPPControl.h +++ b/src/add-ons/kernel/network/ppp/shared/libkernelppp/headers/PPPControl.h @@ -1,5 +1,5 @@ /* - * Copyright 2003-2004, Haiku Inc. + * Copyright 2003-2005, Haiku Inc. * Distributed under the terms of the MIT License. */ @@ -46,11 +46,14 @@ enum ppp_control_ops { // ----------------------------------------------------- // KPPPInterface PPPC_GET_INTERFACE_INFO = PPP_INTERFACE_OPS_START, + PPPC_SET_USERNAME, + PPPC_SET_PASSWORD, + PPPC_SET_ASK_BEFORE_CONNECTING, + // ppp_up uses this in order to finalize a connection request PPPC_SET_MRU, PPPC_SET_CONNECT_ON_DEMAND, PPPC_SET_AUTO_RECONNECT, PPPC_HAS_INTERFACE_SETTINGS, - PPPC_SET_PROFILE, PPPC_GET_STATISTICS, // handler access @@ -96,8 +99,6 @@ typedef struct ppp_interface_description_info { const char *name; //!< Name of interface description file. } u; - const driver_settings *profile; - //!< An optional profile. If \a profile == NULL the default profile is used. ppp_interface_id interface; //!< The id of the found/created interface. } ppp_interface_description_info; @@ -152,13 +153,14 @@ typedef struct ppp_interface_info { uint32 protocolsCount, optionHandlersCount, LCPExtensionsCount, childrenCount; uint32 MRU, interfaceMTU; - uint32 connectRetry, connectRetriesLimit; + uint32 connectAttempt, connectRetriesLimit; uint32 connectRetryDelay, reconnectDelay; bigtime_t connectedSince; // undefined if disconnected uint32 idleSince, disconnectAfterIdleSince; - bool doesConnectOnDemand, doesAutoReconnect, hasDevice, isMultilink, hasParent; + bool doesConnectOnDemand, doesAutoReconnect, askBeforeConnecting, hasDevice; + bool isMultilink, hasParent; } ppp_interface_info; /*! \brief You \e must use this encapsulator instead of \c ppp_interface_info! diff --git a/src/add-ons/kernel/network/ppp/shared/libkernelppp/headers/PPPDefs.h b/src/add-ons/kernel/network/ppp/shared/libkernelppp/headers/PPPDefs.h index eb674c06b3..6ec06bbefd 100644 --- a/src/add-ons/kernel/network/ppp/shared/libkernelppp/headers/PPPDefs.h +++ b/src/add-ons/kernel/network/ppp/shared/libkernelppp/headers/PPPDefs.h @@ -1,5 +1,5 @@ /* - * Copyright 2003-2004, Haiku Inc. + * Copyright 2003-2005, Haiku Inc. * Distributed under the terms of the MIT License. */ @@ -15,8 +15,9 @@ typedef uint32 ppp_interface_id; // settings keys +#define PPP_USERNAME_KEY "Username" +#define PPP_PASSWORD_KEY "Password" #define PPP_ASK_BEFORE_CONNECTING_KEY "AskBeforeConnecting" - // userland ppp_up and preflet handle this key #define PPP_DISONNECT_AFTER_IDLE_SINCE_KEY "DisonnectAfterIdleSince" #define PPP_MODE_KEY "Mode" #define PPP_CONNECT_RETRIES_LIMIT_KEY "ConnectRetriesLimit" @@ -37,10 +38,10 @@ typedef uint32 ppp_interface_id; #define PPP_MODULES_PATH NETWORK_MODULES_ROOT "ppp" #define PTP_INTERFACE_SETTINGS_PATH \ "/boot/home/config/settings/kernel/drivers/ptpnet" - // should be: /etc/ptpnet + // TODO: should be: /etc/ptpnet #define PTP_SETTINGS_PATH \ "/boot/home/config/settings/kernel/drivers/ptpnet.settings" - // should be: /etc/ptpnet.settings + // TODO: should be: /etc/ptpnet.settings // built-in protocols #define PPP_LCP_PROTOCOL 0xC021 diff --git a/src/add-ons/kernel/network/ppp/shared/libkernelppp/headers/PPPReportDefs.h b/src/add-ons/kernel/network/ppp/shared/libkernelppp/headers/PPPReportDefs.h index ffb84b05ca..68e0d94862 100644 --- a/src/add-ons/kernel/network/ppp/shared/libkernelppp/headers/PPPReportDefs.h +++ b/src/add-ons/kernel/network/ppp/shared/libkernelppp/headers/PPPReportDefs.h @@ -1,5 +1,5 @@ /* - * Copyright 2003-2004, Haiku Inc. + * Copyright 2003-2005, Haiku Inc. * Distributed under the terms of the MIT License. */ @@ -16,19 +16,10 @@ #define PPP_REPORT_CODE '_3PR' // the code of receive_data() must have this value -//! Sends a reply to the report message sender. -#define PPP_REPLY(sender, value) \ - send_data_with_timeout((sender), (value), NULL, 0, PPP_REPORT_TIMEOUT) - -#define PPP_OK_DISABLE_REPORTS 'OKDR' - // additional reply code (B_OK should be used) - //! Report flags. enum ppp_report_flags { - PPP_WAIT_FOR_REPLY = 0x01, - PPP_REMOVE_AFTER_REPORT = 0x02, - PPP_NO_REPLY_TIMEOUT = 0x04, - PPP_ALLOW_ANY_REPLY_THREAD = 0x08 + PPP_REMOVE_AFTER_REPORT = 0x01, + PPP_REGISTER_SUBITEMS = 0x02 }; // report types @@ -57,15 +48,10 @@ enum ppp_connection_report_codes { PPP_REPORT_GOING_UP = 0, PPP_REPORT_UP_SUCCESSFUL = 1, PPP_REPORT_DOWN_SUCCESSFUL = 2, - PPP_REPORT_UP_ABORTED = 3, - PPP_REPORT_DEVICE_UP_FAILED = 4, - PPP_REPORT_LOCAL_AUTHENTICATION_REQUESTED = 5, - PPP_REPORT_PEER_AUTHENTICATION_REQUESTED = 6, - PPP_REPORT_LOCAL_AUTHENTICATION_SUCCESSFUL = 7, - PPP_REPORT_PEER_AUTHENTICATION_SUCCESSFUL = 8, - PPP_REPORT_LOCAL_AUTHENTICATION_FAILED = 9, - PPP_REPORT_PEER_AUTHENTICATION_FAILED = 10, - PPP_REPORT_CONNECTION_LOST = 11 + PPP_REPORT_DEVICE_UP_FAILED = 3, + PPP_REPORT_AUTHENTICATION_REQUESTED = 4, + PPP_REPORT_AUTHENTICATION_FAILED = 5, + PPP_REPORT_CONNECTION_LOST = 6 }; diff --git a/src/add-ons/kernel/network/ppp/shared/libkernelppp/headers/settings_tools.h b/src/add-ons/kernel/network/ppp/shared/libkernelppp/headers/settings_tools.h index a7ba50b928..b3439ff8f6 100644 --- a/src/add-ons/kernel/network/ppp/shared/libkernelppp/headers/settings_tools.h +++ b/src/add-ons/kernel/network/ppp/shared/libkernelppp/headers/settings_tools.h @@ -1,5 +1,5 @@ /* - * Copyright 2003-2004, Waldemar Kornewald + * Copyright 2003-2004, Waldemar Kornewald * Distributed under the terms of the MIT License. */ diff --git a/src/add-ons/kernel/network/ppp/shared/libkernelppp/settings_tools.cpp b/src/add-ons/kernel/network/ppp/shared/libkernelppp/settings_tools.cpp index d104b6b2e5..f70c277f41 100644 --- a/src/add-ons/kernel/network/ppp/shared/libkernelppp/settings_tools.cpp +++ b/src/add-ons/kernel/network/ppp/shared/libkernelppp/settings_tools.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2003-2004, Waldemar Kornewald + * Copyright 2003-2004, Waldemar Kornewald * Distributed under the terms of the MIT License. */ diff --git a/src/add-ons/kernel/network/ppp/shared/libppp/Jamfile b/src/add-ons/kernel/network/ppp/shared/libppp/Jamfile index 4a07f41f48..89c2faacf6 100644 --- a/src/add-ons/kernel/network/ppp/shared/libppp/Jamfile +++ b/src/add-ons/kernel/network/ppp/shared/libppp/Jamfile @@ -1,7 +1,6 @@ SubDir OBOS_TOP src add-ons kernel network ppp shared libppp ; UsePrivateHeaders net ; -UseHeaders [ FDirName $(OBOS_TOP) src servers net ] ; UseHeaders [ FDirName $(OBOS_TOP) src add-ons kernel network ppp shared libppp headers ] ; UseHeaders [ FDirName $(OBOS_TOP) src add-ons kernel network ppp shared libkernelppp headers ] ; @@ -16,6 +15,7 @@ StaticLibrary ppp : PPPInterface.cpp PPPInterfaceListener.cpp PPPManager.cpp + MessageDriverSettingsUtils.cpp ; SEARCH on [ FGristFiles strlcat.c ] = [ FDirName $(OBOS_TOP) src system libroot posix string ] ; diff --git a/src/tests/kits/net/DialUpPreflet/MessageDriverSettingsUtils.cpp b/src/add-ons/kernel/network/ppp/shared/libppp/MessageDriverSettingsUtils.cpp similarity index 98% rename from src/tests/kits/net/DialUpPreflet/MessageDriverSettingsUtils.cpp rename to src/add-ons/kernel/network/ppp/shared/libppp/MessageDriverSettingsUtils.cpp index 576f7eeb21..f8f978d03e 100644 --- a/src/tests/kits/net/DialUpPreflet/MessageDriverSettingsUtils.cpp +++ b/src/add-ons/kernel/network/ppp/shared/libppp/MessageDriverSettingsUtils.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2004, Waldemar Kornewald + * Copyright 2004, Waldemar Kornewald * Distributed under the terms of the MIT License. */ diff --git a/src/add-ons/kernel/network/ppp/shared/libppp/PPPInterface.cpp b/src/add-ons/kernel/network/ppp/shared/libppp/PPPInterface.cpp index 6f7aed5da6..f08f8f438a 100644 --- a/src/add-ons/kernel/network/ppp/shared/libppp/PPPInterface.cpp +++ b/src/add-ons/kernel/network/ppp/shared/libppp/PPPInterface.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2003-2004, Waldemar Kornewald + * Copyright 2003-2005, Waldemar Kornewald * Distributed under the terms of the MIT License. */ @@ -140,6 +140,42 @@ PPPInterface::Control(uint32 op, void *data, size_t length) const } +//! Sets the username used for authentication. +bool +PPPInterface::SetUsername(const char *username) const +{ + if(InitCheck() != B_OK || !username) + return false; + + return Control(PPPC_SET_USERNAME, const_cast(username), strlen(username)) + == B_OK; +} + + +//! Sets the password used for authentication. +bool +PPPInterface::SetPassword(const char *password) const +{ + if(InitCheck() != B_OK || !password) + return false; + + return Control(PPPC_SET_PASSWORD, const_cast(password), strlen(password)) + == B_OK; +} + + +//! Sets whether a request window should be shown before connecting. +bool +PPPInterface::SetAskBeforeConnecting(bool askBeforeConnecting) const +{ + if(InitCheck() != B_OK) + return false; + + uint32 value = askBeforeConnecting ? 1 : 0; + return Control(PPPC_SET_ASK_BEFORE_CONNECTING, &value, sizeof(value)) == B_OK; +} + + /*! \brief Find BEntry to the interface settings that this object represents. \param entry The entry gets stored in this argument. @@ -212,23 +248,6 @@ PPPInterface::HasSettings(const driver_settings *settings) const } -/*! \brief Changes the current interface profile. - - You may change the interface's profile at any time. The changes take effect when - the interface connects. - - \param profile The new profile. -*/ -void -PPPInterface::SetProfile(const driver_settings *profile) const -{ - if(InitCheck() != B_OK || !profile) - return; - - Control(PPPC_SET_PROFILE, const_cast(profile), 0); -} - - //! Brings the interface up. bool PPPInterface::Up() const diff --git a/src/add-ons/kernel/network/ppp/shared/libppp/PPPInterfaceListener.cpp b/src/add-ons/kernel/network/ppp/shared/libppp/PPPInterfaceListener.cpp index 60ca0b538c..16041178aa 100644 --- a/src/add-ons/kernel/network/ppp/shared/libppp/PPPInterfaceListener.cpp +++ b/src/add-ons/kernel/network/ppp/shared/libppp/PPPInterfaceListener.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2003-2004, Waldemar Kornewald + * Copyright 2003-2005, Waldemar Kornewald * Distributed under the terms of the MIT License. */ @@ -8,16 +8,10 @@ PPPInterfaceListener converts all kernel report messages from the PPP stack into BMessage objects and forwards them to the target BHandler.\n - In case the BLooper's message queue is full and does not respond after a timeout - period it sends the reply message to the PPP stack for you. Otherwise you must - do it yourself.\n - Of course you can use this class to watch for all interfaces. This includes - automatically adding newly created interfaces to the watch-list.\n The following values are added to each BMessage as int32 values: - - "sender": the thread_id of the report sender (your reply target) - - "interface" (optional): the interface ID of the affected interface - - "type": the report type - - "code": the report code + - "interface" [\c int32] (optional): the interface ID of the affected interface + - "type" [\c int32]: the report type + - "code" [\c int32]: the report code */ #include "PPPInterfaceListener.h" @@ -30,98 +24,62 @@ #include -static const uint32 kReportFlags = PPP_WAIT_FOR_REPLY | PPP_NO_REPLY_TIMEOUT - | PPP_ALLOW_ANY_REPLY_THREAD; - static const int32 kCodeQuitReportThread = 'QUIT'; -//! Private class. -class PPPInterfaceListenerThread { - public: - PPPInterfaceListenerThread(PPPInterfaceListener *listener) - : fListener(listener) {} - - status_t Run(); - - private: - PPPInterfaceListener *fListener; -}; - - +// Creates a BMessage for each report and send it to the target BHandler. +static status_t -PPPInterfaceListenerThread::Run() +report_thread(void *data) { - ppp_report_packet packet; + PPPInterfaceListener *listener = static_cast(data); + + ppp_report_packet report; ppp_interface_id *interfaceID; int32 code; thread_id sender; - BMessage message; - bool sendMessage; while(true) { - code = receive_data(&sender, &packet, sizeof(packet)); + code = receive_data(&sender, &report, sizeof(report)); if(code == kCodeQuitReportThread) break; else if(code != PPP_REPORT_CODE) continue; - BMessenger messenger(fListener->Target()); - sendMessage = messenger.IsValid(); - - if(sendMessage) { + BMessenger messenger(listener->Target()); + if(messenger.IsValid()) { message.MakeEmpty(); - message.what = PPP_REPORT_MESSAGE; - message.AddInt32("sender", sender); - message.AddInt32("type", packet.type); - message.AddInt32("code", packet.code); + message.AddInt32("type", report.type); + message.AddInt32("code", report.code); - if(packet.length >= sizeof(ppp_interface_id) - && ((packet.type == PPP_MANAGER_REPORT - && packet.code == PPP_REPORT_INTERFACE_CREATED) - || packet.type >= PPP_INTERFACE_REPORT_TYPE_MIN)) { - interfaceID = reinterpret_cast(packet.data); + if(report.length >= sizeof(ppp_interface_id) + && ((report.type == PPP_MANAGER_REPORT + && report.code == PPP_REPORT_INTERFACE_CREATED) + || report.type >= PPP_INTERFACE_REPORT_TYPE_MIN)) { + interfaceID = reinterpret_cast(report.data); message.AddInt32("interface", static_cast(*interfaceID)); } - // We might cause a dead-lock. Thus, abort if we cannot get the lock. - BHandler *noHandler = NULL; - // needed to tell compiler which version of SendMessage we want - if(messenger.SendMessage(&message, noHandler, 100000) != B_OK) - PPP_REPLY(sender, B_OK); - } else - PPP_REPLY(sender, B_OK); + // We might cause a dead-lock. Thus, abort if we cannot send. + messenger.SendMessage(&message, (BHandler*) NULL, 100000); + } } return B_OK; } -static -status_t -report_thread(void *data) -{ - // Create BMessage for each report and send it to the target BHandler. - // The target must send a reply to the interface! - - PPPInterfaceListenerThread *thread - = static_cast(data); - - return thread->Run(); -} - - /*! \brief Constructs a new listener that sends report messages to \a target. \param target The target BHandler which should receive report messages. */ PPPInterfaceListener::PPPInterfaceListener(BHandler *target) : fTarget(target), - fDoesWatch(false), - fWatchingInterface(PPP_UNDEFINED_INTERFACE_ID) + fIsWatching(false), + fInterface(PPP_UNDEFINED_INTERFACE_ID) { Construct(); } @@ -130,8 +88,8 @@ PPPInterfaceListener::PPPInterfaceListener(BHandler *target) //! Copy constructor. PPPInterfaceListener::PPPInterfaceListener(const PPPInterfaceListener& copy) : fTarget(copy.Target()), - fDoesWatch(false), - fWatchingInterface(PPP_UNDEFINED_INTERFACE_ID) + fIsWatching(false), + fInterface(PPP_UNDEFINED_INTERFACE_ID) { Construct(); } @@ -141,8 +99,8 @@ PPPInterfaceListener::PPPInterfaceListener(const PPPInterfaceListener& copy) PPPInterfaceListener::~PPPInterfaceListener() { // disable all report messages - StopWatchingInterfaces(); - Manager().DisableReports(PPP_ALL_REPORTS, fReportThread); + StopWatchingInterface(); + StopWatchingManager(); // tell thread to quit send_data(fReportThread, kCodeQuitReportThread, NULL, 0); @@ -174,9 +132,7 @@ PPPInterfaceListener::InitCheck() const void PPPInterfaceListener::SetTarget(BHandler *target) { - LockerHelper locker(fLock); - - target = fTarget; + fTarget = target; } @@ -191,93 +147,61 @@ PPPInterfaceListener::SetTarget(BHandler *target) bool PPPInterfaceListener::WatchInterface(ppp_interface_id ID) { - StopWatchingInterfaces(); + StopWatchingInterface(); // enable reports PPPInterface interface(ID); if(interface.InitCheck() != B_OK) return false; - if(!interface.EnableReports(PPP_CONNECTION_REPORT, fReportThread, kReportFlags)) + if(!interface.EnableReports(PPP_CONNECTION_REPORT, fReportThread, PPP_NO_FLAGS)) return false; - fDoesWatch = true; - fWatchingInterface = ID; + fIsWatching = true; + fInterface = ID; return true; } -//! Enables mode for watching all interfaces. New interfaces are added automatically. +//! Enables interface creation messages from the PPP manager. void -PPPInterfaceListener::WatchAllInterfaces() +PPPInterfaceListener::WatchManager() { - StopWatchingInterfaces(); - - // enable interface reports - int32 count; - PPPInterface interface; - ppp_interface_id *interfaceList; - - interfaceList = Manager().Interfaces(&count); - if(!interfaceList) - return; - - for(int32 index = 0; index < count; index++) { - interface.SetTo(interfaceList[index]); - interface.EnableReports(PPP_CONNECTION_REPORT, fReportThread, kReportFlags); - } - delete interfaceList; - - fDoesWatch = true; - fWatchingInterface = PPP_UNDEFINED_INTERFACE_ID; - // this means watching all + Manager().EnableReports(PPP_MANAGER_REPORT, fReportThread, PPP_NO_FLAGS); } -/*! \brief Stops watching interfaces. +/*! \brief Stops watching the interface. - Beware that this does not disable the PPP stack's own report messages (e.g.: new - interfaces that being created). + Beware that this does not disable the PPP manager's report messages. */ void -PPPInterfaceListener::StopWatchingInterfaces() +PPPInterfaceListener::StopWatchingInterface() { - if(!fDoesWatch) + if(!fIsWatching) return; - if(fWatchingInterface == PPP_UNDEFINED_INTERFACE_ID) { - // disable all reports - int32 count; - PPPInterface interface; - ppp_interface_id *interfaceList; - - interfaceList = Manager().Interfaces(&count); - if(!interfaceList) - return; - - for(int32 index = 0; index < count; index++) { - interface.SetTo(interfaceList[index]); - interface.DisableReports(PPP_ALL_REPORTS, fReportThread); - } - delete interfaceList; - } else { - PPPInterface interface(fWatchingInterface); - interface.DisableReports(PPP_ALL_REPORTS, fReportThread); - } + PPPInterface interface(fInterface); + interface.DisableReports(PPP_ALL_REPORTS, fReportThread); - fDoesWatch = false; - fWatchingInterface = PPP_UNDEFINED_INTERFACE_ID; + fIsWatching = false; + fInterface = PPP_UNDEFINED_INTERFACE_ID; +} + + +//! Disables interface creation messages from the PPP manager. +void +PPPInterfaceListener::StopWachingManager() +{ + Manager().DisableReports(PPP_ALL_REPORTS, fReportThread); } void PPPInterfaceListener::Construct() { - fReportThread = spawn_thread(report_thread, "report_thread", - B_NORMAL_PRIORITY, new PPPInterfaceListenerThread(this)); + fReportThread = spawn_thread(report_thread, "report_thread", B_NORMAL_PRIORITY, + this); resume_thread(fReportThread); - - // enable manager reports - Manager().EnableReports(PPP_MANAGER_REPORT, fReportThread, kReportFlags); } diff --git a/src/add-ons/kernel/network/ppp/shared/libppp/PPPManager.cpp b/src/add-ons/kernel/network/ppp/shared/libppp/PPPManager.cpp index f616004d9f..37af77b98d 100644 --- a/src/add-ons/kernel/network/ppp/shared/libppp/PPPManager.cpp +++ b/src/add-ons/kernel/network/ppp/shared/libppp/PPPManager.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2003-2004, Waldemar Kornewald + * Copyright 2003-2005, Waldemar Kornewald * Distributed under the terms of the MIT License. */ @@ -12,6 +12,11 @@ #include "PPPManager.h" #include "PPPInterface.h" +#include "MessageDriverSettingsUtils.h" + +#include +#include +#include #include #include @@ -36,6 +41,69 @@ PPPManager::~PPPManager() } +//! Sets the default interface. +bool +PPPManager::SetDefaultInterface(const BString name) +{ + // load current settings and replace value of "default" with + BMessage settings; + if(!ReadMessageDriverSettings("ptpnet.settings", &settings)) + settings.MakeEmpty(); + + BMessage parameter; + int32 index = 0; + if(FindMessageParameter("default", settings, ¶meter, &index)) + settings.RemoveData(MDSU_PARAMETERS, index); + + parameter.MakeEmpty(); + if(name != "") { + parameter.AddString(MDSU_NAME, "default"); + parameter.AddString(MDSU_VALUES, name); + settings.AddMessage(MDSU_PARAMETERS, ¶meter); + } + + BFile file(PTP_SETTINGS_PATH, B_WRITE_ONLY | B_CREATE_FILE | B_ERASE_FILE); + if(file.InitCheck() != B_OK) + return false; + + if(WriteMessageDriverSettings(file, settings)) + return true; + else + return false; +} + + +//! Returns the name of the default interface. +BString +PPPManager::DefaultInterface() +{ + void *handle = load_driver_settings("ptpnet.settings"); + BString name = get_driver_parameter(handle, "default", NULL, NULL); + unload_driver_settings(handle); + return name; +} + + +//! Sets the given BDirectory to the settings folder. +bool +PPPManager::GetSettingsDirectory(BDirectory *settingsDirectory) +{ + if(settingsDirectory) { + BDirectory settings(PTP_INTERFACE_SETTINGS_PATH); + if(settings.InitCheck() != B_OK) { + create_directory(PTP_INTERFACE_SETTINGS_PATH, 0750); + settings.SetTo(PTP_INTERFACE_SETTINGS_PATH); + if(settings.InitCheck() != B_OK) + return false; + } + + *settingsDirectory = settings; + } + + return true; +} + + //! Returns \c B_OK if created successfully and \c B_ERROR otherwise. status_t PPPManager::InitCheck() const @@ -109,19 +177,17 @@ PPPManager::ControlModule(const char *name, uint32 op, void *data, } -/*! \brief Creates a nameless interface with the given settings and profile. +/*! \brief Creates a nameless interface with the given settings. Please use \c CreateInterfaceWithName() instead of this method. \return the new interface's ID or \c PPP_UNDEFINED_INTERFACE_ID on failure. */ ppp_interface_id -PPPManager::CreateInterface(const driver_settings *settings, - const driver_settings *profile = NULL) const +PPPManager::CreateInterface(const driver_settings *settings) const { ppp_interface_description_info info; info.u.settings = settings; - info.profile = profile; if(Control(PPPC_CREATE_INTERFACE, &info, sizeof(info)) != B_OK) return PPP_UNDEFINED_INTERFACE_ID; @@ -130,29 +196,19 @@ PPPManager::CreateInterface(const driver_settings *settings, } -/*! \brief Creates an interface with the given name and profile. +/*! \brief Creates an interface with the given name. If the interface already exists its ID will be returned. - Every PPP interface has a profile. By default it checks if the ptpnet/profile - folder contains a profile with the interface's name. Otherwise the interface's - settings become its profile. This has the advantage that you can put the profile - and the settings into the same file which simplifies your PPP configuration if - you edit your PPP interface definitions by hand. In this case PAP, for example, - would still find the username and password although you specify them in the same - parameter that loads the PAP module. \param name The PPP interface description file's name. - \param profile You may override the default profile. \return the new interface's ID or \c PPP_UNDEFINED_INTERFACE_ID on failure. */ ppp_interface_id -PPPManager::CreateInterfaceWithName(const char *name, - const driver_settings *profile = NULL) const +PPPManager::CreateInterfaceWithName(const char *name) const { ppp_interface_description_info info; info.u.name = name; - info.profile = profile; if(Control(PPPC_CREATE_INTERFACE_WITH_NAME, &info, sizeof(info)) != B_OK) return PPP_UNDEFINED_INTERFACE_ID; diff --git a/src/add-ons/kernel/network/ppp/shared/libppp/_libppputils.cpp b/src/add-ons/kernel/network/ppp/shared/libppp/_libppputils.cpp index e503722910..6de6e33cee 100644 --- a/src/add-ons/kernel/network/ppp/shared/libppp/_libppputils.cpp +++ b/src/add-ons/kernel/network/ppp/shared/libppp/_libppputils.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2003-2004, Waldemar Kornewald + * Copyright 2003-2004, Waldemar Kornewald * Distributed under the terms of the MIT License. */ diff --git a/src/add-ons/kernel/network/ppp/shared/libppp/_libppputils.h b/src/add-ons/kernel/network/ppp/shared/libppp/_libppputils.h index 3c938b24c1..91bd4c7f7c 100644 --- a/src/add-ons/kernel/network/ppp/shared/libppp/_libppputils.h +++ b/src/add-ons/kernel/network/ppp/shared/libppp/_libppputils.h @@ -1,5 +1,5 @@ /* - * Copyright 2003-2004, Waldemar Kornewald + * Copyright 2003-2005, Waldemar Kornewald * Distributed under the terms of the MIT License. */ @@ -7,10 +7,6 @@ #define __libppputils__h #include -#include - - -#define PPP_SERVER_SIGNATURE NET_SERVER_SIGNATURE char *get_stack_driver_path(); diff --git a/src/tests/kits/net/DialUpPreflet/MessageDriverSettingsUtils.h b/src/add-ons/kernel/network/ppp/shared/libppp/headers/MessageDriverSettingsUtils.h similarity index 91% rename from src/tests/kits/net/DialUpPreflet/MessageDriverSettingsUtils.h rename to src/add-ons/kernel/network/ppp/shared/libppp/headers/MessageDriverSettingsUtils.h index 8bc49d446b..23aa23e4c9 100644 --- a/src/tests/kits/net/DialUpPreflet/MessageDriverSettingsUtils.h +++ b/src/add-ons/kernel/network/ppp/shared/libppp/headers/MessageDriverSettingsUtils.h @@ -1,5 +1,5 @@ /* - * Copyright 2004, Waldemar Kornewald + * Copyright 2004, Waldemar Kornewald * Distributed under the terms of the MIT License. */ diff --git a/src/add-ons/kernel/network/ppp/shared/libppp/headers/PPPInterface.h b/src/add-ons/kernel/network/ppp/shared/libppp/headers/PPPInterface.h index ae1a51fe17..47bafecee0 100644 --- a/src/add-ons/kernel/network/ppp/shared/libppp/headers/PPPInterface.h +++ b/src/add-ons/kernel/network/ppp/shared/libppp/headers/PPPInterface.h @@ -1,5 +1,5 @@ /* - * Copyright 2003-2004, Haiku Inc. + * Copyright 2003-2005, Haiku Inc. * Distributed under the terms of the MIT License. */ @@ -30,13 +30,15 @@ class PPPInterface { status_t Control(uint32 op, void *data, size_t length) const; + bool SetUsername(const char *username) const; + bool SetPassword(const char *password) const; + bool SetAskBeforeConnecting(bool askBeforeConnecting) const; + status_t GetSettingsEntry(BEntry *entry) const; bool GetInterfaceInfo(ppp_interface_info_t *info) const; bool GetStatistics(ppp_statistics *statistics) const; bool HasSettings(const driver_settings *settings) const; - void SetProfile(const driver_settings *profile) const; - bool Up() const; bool Down() const; diff --git a/src/add-ons/kernel/network/ppp/shared/libppp/headers/PPPInterfaceListener.h b/src/add-ons/kernel/network/ppp/shared/libppp/headers/PPPInterfaceListener.h index cb69567ab1..0645c53f2f 100644 --- a/src/add-ons/kernel/network/ppp/shared/libppp/headers/PPPInterfaceListener.h +++ b/src/add-ons/kernel/network/ppp/shared/libppp/headers/PPPInterfaceListener.h @@ -1,5 +1,5 @@ /* - * Copyright 2003-2004, Haiku Inc. + * Copyright 2003-2005, Haiku Inc. * Distributed under the terms of the MIT License. */ @@ -17,8 +17,6 @@ class BHandler; class PPPInterfaceListener { - friend class PPPInterfaceListenerThread; - public: PPPInterfaceListener(BHandler *target); PPPInterfaceListener(const PPPInterfaceListener& copy); @@ -31,20 +29,21 @@ class PPPInterfaceListener { { return fTarget; } void SetTarget(BHandler *target); - //! Returns whether watching an interface. - bool DoesWatch() const - { return fDoesWatch; } + //! Returns whether the listener is watching an interface. + bool IsWatching() const + { return fIsWatching; } //! Returns which interface is being watched or \c PPP_UNDEFINED_INTERFACE_ID. - ppp_interface_id WatchingInterface() const - { return fWatchingInterface; } + ppp_interface_id Interface() const + { return fInterface; } //! Returns the internal PPPManager object used for accessing the PPP stack. const PPPManager& Manager() const { return fManager; } bool WatchInterface(ppp_interface_id ID); - void WatchAllInterfaces(); - void StopWatchingInterfaces(); + void WatchManager(); + void StopWatchingInterface(); + void StopWatchingManager(); //! Just sets the target to the given listener's target. PPPInterfaceListener& operator= (const PPPInterfaceListener& copy) @@ -57,11 +56,10 @@ class PPPInterfaceListener { BHandler *fTarget; thread_id fReportThread; - bool fDoesWatch; - ppp_interface_id fWatchingInterface; + bool fIsWatching; + ppp_interface_id fInterface; PPPManager fManager; - BLocker fLock; }; diff --git a/src/add-ons/kernel/network/ppp/shared/libppp/headers/PPPManager.h b/src/add-ons/kernel/network/ppp/shared/libppp/headers/PPPManager.h index 1996eadee0..b3ae547202 100644 --- a/src/add-ons/kernel/network/ppp/shared/libppp/headers/PPPManager.h +++ b/src/add-ons/kernel/network/ppp/shared/libppp/headers/PPPManager.h @@ -1,5 +1,5 @@ /* - * Copyright 2003-2004, Haiku Inc. + * Copyright 2003-2005, Haiku Inc. * Distributed under the terms of the MIT License. */ @@ -7,6 +7,7 @@ #define _PPP_MANAGER__H #include +#include class PPPManager { @@ -19,16 +20,18 @@ class PPPManager { PPPManager(); ~PPPManager(); + static bool SetDefaultInterface(const BString name); + static BString DefaultInterface(); + static bool GetSettingsDirectory(BDirectory *settingsDirectory); + status_t InitCheck() const; status_t Control(uint32 op, void *data, size_t length) const; status_t ControlModule(const char *name, uint32 op, void *data, size_t length) const; - ppp_interface_id CreateInterface(const driver_settings *settings, - const driver_settings *profile = NULL) const; - ppp_interface_id CreateInterfaceWithName(const char *name, - const driver_settings *profile = NULL) const; + ppp_interface_id CreateInterface(const driver_settings *settings) const; + ppp_interface_id CreateInterfaceWithName(const char *name) const; bool DeleteInterface(ppp_interface_id ID) const; ppp_interface_id *Interfaces(int32 *count, diff --git a/src/bin/Jamfile b/src/bin/Jamfile index 79cbaedd9e..32323e3e86 100644 --- a/src/bin/Jamfile +++ b/src/bin/Jamfile @@ -140,7 +140,6 @@ SubInclude OBOS_TOP src bin rcs ; # Network command line tools SubInclude OBOS_TOP src bin arp ; SubInclude OBOS_TOP src bin ifconfig ; -SubInclude OBOS_TOP src bin ppp_up ; SubInclude OBOS_TOP src bin pppconfig ; SubInclude OBOS_TOP src bin ping ; SubInclude OBOS_TOP src bin route ; diff --git a/src/bin/ppp_up/ConnectionView.cpp b/src/bin/ppp_up/ConnectionView.cpp deleted file mode 100644 index 02ef257af6..0000000000 --- a/src/bin/ppp_up/ConnectionView.cpp +++ /dev/null @@ -1,350 +0,0 @@ -/* - * Copyright 2004, Waldemar Kornewald - * Distributed under the terms of the MIT License. - */ - -#include "ConnectionView.h" -#include - -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include - // for max() - - -// GUI constants -static const uint32 kDefaultButtonWidth = 80; - -// message constants -static const uint32 kMsgCancel = 'CANC'; -static const uint32 kMsgConnect = 'CONN'; - -// labels -static const char *kLabelSavePassword = "Save Password"; -static const char *kLabelName = "Username: "; -static const char *kLabelPassword = "Password: "; -static const char *kLabelConnect = "Connect"; -static const char *kLabelCancel = "Cancel"; -static const char *kLabelAuthentication = "Authentication"; - -// connection status strings -static const char *kTextConnecting = "Connecting..."; -static const char *kTextConnectionEstablished = "Connection established."; -static const char *kTextNotConnected = "Not connected."; -static const char *kTextDeviceUpFailed = "Failed to connect."; -static const char *kTextAuthenticating = "Authenticating..."; -static const char *kTextAuthenticationFailed = "Authentication failed!"; -static const char *kTextConnectionLost = "Connection lost!"; - - -static -status_t -up_thread(void *data) -{ - PPPInterface *interface = static_cast(data); - interface->Up(); - delete interface; - return B_OK; -} - - -static -status_t -down_thread(void *data) -{ - PPPInterface *interface = static_cast(data); - interface->Down(); - delete interface; - return B_OK; -} - - -ConnectionView::ConnectionView(BRect rect, const char *name, ppp_interface_id id, - thread_id thread) - : BView(rect, "ConnectionView", B_FOLLOW_NONE, 0), - fInterfaceName(name), - fID(id), - fReportThread(thread), - fConnecting(false), - fKeepLabel(false), - fReplyRequested(true) -{ - SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR)); - - rect = Bounds(); - rect.InsetBy(5, 5); - rect.bottom = rect.top - + 25 // space for topmost control - + 3 * 20 // size of controls - + 3 * 5; // space beween controls and bottom of box - BBox *authenticationBox = new BBox(rect, "Authentication"); - authenticationBox->SetLabel(kLabelAuthentication); - rect = authenticationBox->Bounds(); - rect.InsetBy(10, 20); - rect.bottom = rect.top + 20; - fUsername = new BTextControl(rect, "username", kLabelName, NULL, NULL); - rect.top = rect.bottom + 5; - rect.bottom = rect.top + 20; - fPassword = new BTextControl(rect, "password", kLabelPassword, NULL, NULL); - fPassword->TextView()->HideTyping(true); - - // set dividers - float width = max(StringWidth(fUsername->Label()), - StringWidth(fPassword->Label())); - fUsername->SetDivider(width + 5); - fPassword->SetDivider(width + 5); - - rect.top = rect.bottom + 5; - rect.bottom = rect.top + 20; - fSavePassword = new BCheckBox(rect, "SavePassword", kLabelSavePassword, NULL); - - authenticationBox->AddChild(fUsername); - authenticationBox->AddChild(fPassword); - authenticationBox->AddChild(fSavePassword); - AddChild(authenticationBox); - - rect = authenticationBox->Frame(); - rect.top = rect.bottom + 10; - rect.bottom = rect.top + 15; - fAttemptView = new BStringView(rect, "AttemptView", AttemptString().String()); - AddChild(fAttemptView); - - // add status view - rect.top = rect.bottom + 5; - rect.bottom = rect.top + 15; - fStatusView = new BStringView(rect, "StatusView", ""); - AddChild(fStatusView); - - // add "Connect" and "Cancel" buttons - rect.top = rect.bottom + 10; - rect.bottom = rect.top + 25; - rect.right = rect.left + kDefaultButtonWidth; - fConnectButton = new BButton(rect, "ConnectButton", kLabelConnect, - new BMessage(kMsgConnect)); - Window()->SetDefaultButton(fConnectButton); - - rect.left = rect.right + 10; - rect.right = rect.left + kDefaultButtonWidth; - fCancelButton = new BButton(rect, "CancelButton", kLabelCancel, - new BMessage(kMsgCancel)); - - AddChild(fConnectButton); - AddChild(fCancelButton); - - // initialize PTPSettings - fSettings.LoadAddons(false); - // add PPPUpAddon - fAddon = new PPPUpAddon(&fSettings.Addons(), this); - fSettings.Addons().AddPointer(DUN_TAB_ADDON_TYPE, fAddon); - fSettings.Addons().AddPointer(DUN_DELETE_ON_QUIT, fAddon); -} - - -void -ConnectionView::AttachedToWindow() -{ - fConnectButton->SetTarget(this); - fCancelButton->SetTarget(this); - fSettings.LoadSettings(fInterfaceName.String(), false); - - if(fAddon->CountAuthenticators() == 0 || fAddon->HasPassword() - || fAddon->AskBeforeConnecting()) - Connect(); -} - - -void -ConnectionView::MessageReceived(BMessage *message) -{ - switch(message->what) { - case MSG_UPDATE: { - UpdateStatus(message->FindInt32("code")); - ppp_interface_id id; - if(message->FindInt32("interface", reinterpret_cast(&id)) == B_OK) - fID = id; - } break; - - case MSG_REPLY: - message->SendReply(B_OK); - break; - - case kMsgConnect: - Connect(); - break; - - case kMsgCancel: - Cancel(); - break; - - default: - BView::MessageReceived(message); - } -} - - -// update authentication UI -void -ConnectionView::Reload() -{ - fUsername->SetText(Addon()->Username()); - fPassword->SetText(Addon()->Password()); - fSavePassword->SetValue(Addon()->HasPassword()); - - if(Addon()->CountAuthenticators() > 0) { - fUsername->SetEnabled(true); - fPassword->SetEnabled(true); - fSavePassword->SetEnabled(true); - } else { - fUsername->SetEnabled(false); - fPassword->SetEnabled(false); - fSavePassword->SetEnabled(false); - } -} - - -void -ConnectionView::Connect() -{ - fSettings.SaveSettingsToFile(); - - // update interface profile - BMessage settings, profile; - fSettings.SaveSettings(&settings, &profile, true); - driver_settings *temporaryProfile = MessageToDriverSettings(profile); - PPPInterface *interface = new PPPInterface(PPPManager().CreateInterfaceWithName( - fInterfaceName.String())); - interface->SetProfile(temporaryProfile); - free_driver_settings(temporaryProfile); - - fConnectButton->SetEnabled(false); - fConnecting = true; - - if(fReplyRequested) { - fReplyRequested = false; - send_data(fReportThread, B_OK, NULL, 0); - delete interface; - } else { - thread_id up = spawn_thread(up_thread, "up_thread", B_NORMAL_PRIORITY, - interface); - resume_thread(up); - } -} - - -void -ConnectionView::Cancel() -{ - if(fReplyRequested) { - fReplyRequested = false; - send_data(fReportThread, B_ERROR, NULL, 0); - // tell requestor to cancel connection attempt - } else { - PPPInterface *interface = new PPPInterface(fID); - ppp_interface_info_t info; - interface->GetInterfaceInfo(&info); - - if(info.info.phase < PPP_ESTABLISHED_PHASE) { - thread_id down = spawn_thread(down_thread, "down_thread", - B_NORMAL_PRIORITY, interface); - resume_thread(down); - } else - delete interface; - } -} - - -// Clean up before our window quits (called by ConnectionWindow). -void -ConnectionView::CleanUp() -{ - // TODO: finish clean-up; (DONE?) - if(fReplyRequested) - Cancel(); -} - - -BString -ConnectionView::AttemptString() const -{ - PPPInterface interface(fID); - ppp_interface_info_t info; - interface.GetInterfaceInfo(&info); - BString attempt; - attempt << "Attempt " << info.info.connectRetry << " of " << - info.info.connectRetriesLimit; - - return attempt; -} - - -void -ConnectionView::UpdateStatus(int32 code) -{ - fAttemptView->SetText(AttemptString().String()); - - switch(code) { - case PPP_REPORT_UP_ABORTED: - case PPP_REPORT_DEVICE_UP_FAILED: - case PPP_REPORT_LOCAL_AUTHENTICATION_FAILED: - case PPP_REPORT_PEER_AUTHENTICATION_FAILED: - case PPP_REPORT_DOWN_SUCCESSFUL: - case PPP_REPORT_CONNECTION_LOST: - fConnectButton->SetEnabled(true); - break; - - default: - fConnectButton->SetEnabled(false); - } - - // maybe the status string must not be changed (codes that set fKeepLabel to false - // should still be handled) - if(fKeepLabel && code != PPP_REPORT_GOING_UP && code != PPP_REPORT_UP_SUCCESSFUL) - return; - - // only errors should set fKeepLabel to true - switch(code) { - case PPP_REPORT_GOING_UP: - fKeepLabel = false; - fStatusView->SetText(kTextConnecting); - break; - - case PPP_REPORT_UP_SUCCESSFUL: - fKeepLabel = false; - fStatusView->SetText(kTextConnectionEstablished); - break; - - case PPP_REPORT_UP_ABORTED: - case PPP_REPORT_DOWN_SUCCESSFUL: - fStatusView->SetText(kTextNotConnected); - break; - - case PPP_REPORT_DEVICE_UP_FAILED: - fKeepLabel = true; - fStatusView->SetText(kTextDeviceUpFailed); - break; - - case PPP_REPORT_LOCAL_AUTHENTICATION_REQUESTED: - case PPP_REPORT_PEER_AUTHENTICATION_REQUESTED: - fStatusView->SetText(kTextAuthenticating); - break; - - case PPP_REPORT_LOCAL_AUTHENTICATION_FAILED: - case PPP_REPORT_PEER_AUTHENTICATION_FAILED: - fKeepLabel = true; - fStatusView->SetText(kTextAuthenticationFailed); - break; - - case PPP_REPORT_CONNECTION_LOST: - fKeepLabel = true; - fStatusView->SetText(kTextConnectionLost); - break; - } -} diff --git a/src/bin/ppp_up/ConnectionView.h b/src/bin/ppp_up/ConnectionView.h deleted file mode 100644 index efebd51c67..0000000000 --- a/src/bin/ppp_up/ConnectionView.h +++ /dev/null @@ -1,69 +0,0 @@ -/* - * Copyright 2004, Waldemar Kornewald - * Distributed under the terms of the MIT License. - */ - -#ifndef CONNECTION_VIEW__H -#define CONNECTION_VIEW__H - -#include -#include -#include "PPPUpAddon.h" -#include - - -#define MSG_UPDATE 'MUPD' -#define MSG_REPLY 'MRPY' - - -class ConnectionView : public BView { - friend class ConnectionWindow; - - public: - ConnectionView(BRect rect, const char *name, ppp_interface_id id, - thread_id thread); - - virtual void AttachedToWindow(); - virtual void MessageReceived(BMessage *message); - - // for PPPUpAddon - PPPUpAddon *Addon() const - { return fAddon; } - void Reload(); - const char *Username() const - { return fUsername->Text(); } - const char *Password() const - { return fPassword->Text(); } - bool DoesSavePassword() const - { return fSavePassword->Value(); } - - bool HasTemporaryProfile() const - { return !DoesSavePassword(); } - void IsDeviceModified(bool *settings, bool *profile) const - { if(settings) *settings = false; if(profile) *profile = false; } - - private: - void Connect(); - void Cancel(); - void CleanUp(); - - BString AttemptString() const; - void UpdateStatus(int32 code); - - private: - PPPUpAddon *fAddon; - BString fInterfaceName; - ppp_interface_id fID; - thread_id fReportThread; - - BTextControl *fUsername, *fPassword; - BCheckBox *fSavePassword; - BStringView *fAttemptView, *fStatusView; - BButton *fConnectButton, *fCancelButton; - - bool fConnecting, fKeepLabel, fReplyRequested; - PTPSettings fSettings; -}; - - -#endif diff --git a/src/bin/ppp_up/ConnectionWindow.cpp b/src/bin/ppp_up/ConnectionWindow.cpp deleted file mode 100644 index ff47515e2b..0000000000 --- a/src/bin/ppp_up/ConnectionWindow.cpp +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Copyright 2004-2005, Waldemar Kornewald - * Distributed under the terms of the MIT License. - */ - -#include "ConnectionWindow.h" - -#include -#include - - -ConnectionWindow::ConnectionWindow(BRect frame, const char *name, ppp_interface_id id, - thread_id replyThread) - : BWindow(frame, "", B_TITLED_WINDOW, B_NOT_RESIZABLE | B_NOT_ZOOMABLE, - B_ALL_WORKSPACES) -{ - BString title("Connecting to "); - title << "\"" << name << "\"..."; - SetTitle(title.String()); - fConnectionView = new ConnectionView(Bounds(), name, id, replyThread); - AddChild(fConnectionView); -} - - -bool -ConnectionWindow::QuitRequested() -{ - fConnectionView->CleanUp(); - - be_app->PostMessage(B_QUIT_REQUESTED); - - return true; -} - - -void -ConnectionWindow::UpdateStatus(BMessage& message) -{ - message.what = MSG_UPDATE; - PostMessage(&message, fConnectionView); -} - - -bool -ConnectionWindow::ResponseTest() -{ - // test if we dead-locked - Lock(); - Unlock(); - return true; -} diff --git a/src/bin/ppp_up/ConnectionWindow.h b/src/bin/ppp_up/ConnectionWindow.h deleted file mode 100644 index 884e566fbb..0000000000 --- a/src/bin/ppp_up/ConnectionWindow.h +++ /dev/null @@ -1,29 +0,0 @@ -/* - * Copyright 2004, Waldemar Kornewald - * Distributed under the terms of the MIT License. - */ - -#ifndef CONNECTION_WINDOW__H -#define CONNECTION_WINDOW__H - -#include -#include "ConnectionView.h" - - -class ConnectionWindow : public BWindow { - public: - ConnectionWindow(BRect frame, const char *name, ppp_interface_id id, - thread_id replyThread); - - virtual bool QuitRequested(); - void RequestReply() - { fConnectionView->fReplyRequested = true; } - void UpdateStatus(BMessage& message); - bool ResponseTest(); - - private: - ConnectionView *fConnectionView; -}; - - -#endif diff --git a/src/bin/ppp_up/Jamfile b/src/bin/ppp_up/Jamfile deleted file mode 100644 index e7dd53e6a2..0000000000 --- a/src/bin/ppp_up/Jamfile +++ /dev/null @@ -1,29 +0,0 @@ -SubDir OBOS_TOP src bin ppp_up ; - -UsePrivateHeaders net ; -UseHeaders [ FDirName $(OBOS_TOP) src add-ons kernel network ppp shared libppp headers ] ; -UseHeaders [ FDirName $(OBOS_TOP) src add-ons kernel network ppp shared libkernelppp headers ] ; -UseHeaders [ FDirName $(OBOS_TOP) src tests kits net DialUpPreflet ] ; - -AddResources ppp_up : ppp_up.rdef ; - -BinCommand ppp_up : - ConnectionView.cpp - ConnectionWindow.cpp - PPPDeskbarReplicant.cpp - PPPUpAddon.cpp - PPPUpApplication.cpp - StatusView.cpp - StatusWindow.cpp -; - -LinkSharedOSLibs ppp_up : libptpnet.a libppp.a be ; - -# Installation -OBOSInstall install-networking - : /boot/beos/bin - : ppp_up ; - -Package haiku-networkingkit-cvs : - ppp_up : - boot beos bin ; diff --git a/src/bin/ppp_up/PPPDeskbarReplicant.cpp b/src/bin/ppp_up/PPPDeskbarReplicant.cpp deleted file mode 100644 index 9f3db02f67..0000000000 --- a/src/bin/ppp_up/PPPDeskbarReplicant.cpp +++ /dev/null @@ -1,138 +0,0 @@ -/* - * Copyright 2004-2005, Waldemar Kornewald - * Distributed under the terms of the MIT License. - */ - -#include "PPPDeskbarReplicant.h" - -#include "PPPUpApplication.h" -#include "StatusWindow.h" -#include -#include - -#include -#include - - -// TODO: remove this -/*extern "C" _EXPORT BView *instantiate_deskbar_item(); - -BView* -instantiate_deskbar_item() -{ - return new PPPDeskbarReplicant(); -}*/ - - -static -status_t -destruction_thread(void *data) -{ - thread_id sender; - ppp_report_packet report; - int32 reportCode; - while(true) { - reportCode = receive_data(&sender, &report, sizeof(report)); - if(reportCode != PPP_REPORT_CODE) - continue; - - if(report.type != PPP_DESTRUCTION_REPORT) - continue; - - // our interface has been destroyed, remove the corresponding replicant - // XXX: We do not know which ID the replicant has and there might exist - // multiple connections (replicants)! - BDeskbar().RemoveItem("PPPDeskbarReplicant"); - } - - return B_OK; -} - - -PPPDeskbarReplicant::PPPDeskbarReplicant(ppp_interface_id id) - : BView(BRect(0, 0, 15, 15), "PPPDeskbarReplicant", B_FOLLOW_NONE, 0), - fID(id) -{ - Init(); -} - - -PPPDeskbarReplicant::PPPDeskbarReplicant(BMessage *message) - : BView(BRect(0, 0, 15, 15), "PPPDeskbarReplicant", B_FOLLOW_NONE, 0) -{ - message->FindInt32("interface", reinterpret_cast(&fID)); - Init(); -} - - -PPPDeskbarReplicant::~PPPDeskbarReplicant() -{ - fWindow->LockLooper(); - fWindow->Quit(); -} - - -PPPDeskbarReplicant* -PPPDeskbarReplicant::Instantiate(BMessage *data) -{ - if(!validate_instantiation(data, "PPPDeskbarReplicant")) - return NULL; - - return new PPPDeskbarReplicant(data); -} - - -status_t -PPPDeskbarReplicant::Archive(BMessage *data, bool deep = true) const -{ - BView::Archive(data, deep); - - data->AddString("add_on", APP_SIGNATURE); - data->AddInt32("interface", fID); - return B_NO_ERROR; -} - - -void -PPPDeskbarReplicant::MouseDown(BPoint point) -{ - Looper()->CurrentMessage()->FindInt32("buttons", &fLastButtons); - - // TODO: on secondary mouse button we want to show a pop-up menu -} - - -void -PPPDeskbarReplicant::MouseUp(BPoint point) -{ - if(fLastButtons & B_PRIMARY_MOUSE_BUTTON) { - fWindow->MoveTo(center_on_screen(fWindow->Frame(), fWindow)); - fWindow->Show(); - } -} - - -void -PPPDeskbarReplicant::Draw(BRect updateRect) -{ - // TODO: I want a nice blinking icon! - MovePenTo(4, 12); - DrawString("P"); -} - - -void -PPPDeskbarReplicant::Init() -{ - BRect rect(50,50,380,150); - fWindow = new StatusWindow(rect, fID); - - // watch interface destruction - PPPInterface interface(fID); - if(interface.InitCheck() != B_OK) - return; - - thread_id destructionThread = spawn_thread(destruction_thread, - "destruction_thread", B_NORMAL_PRIORITY, NULL); - interface.EnableReports(PPP_DESTRUCTION_REPORT, destructionThread); -} diff --git a/src/bin/ppp_up/PPPDeskbarReplicant.h b/src/bin/ppp_up/PPPDeskbarReplicant.h deleted file mode 100644 index 0cf1f6109b..0000000000 --- a/src/bin/ppp_up/PPPDeskbarReplicant.h +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright 2004-2005, Waldemar Kornewald - * Distributed under the terms of the MIT License. - */ - -#ifndef PPP_DESKBAR_REPLICANT__H -#define PPP_DESKBAR_REPLICANT__H - -#include -#include - -class StatusWindow; - - -class PPPDeskbarReplicant : public BView { - public: - PPPDeskbarReplicant(ppp_interface_id id); - PPPDeskbarReplicant(BMessage *message); - virtual ~PPPDeskbarReplicant(); - - static PPPDeskbarReplicant *Instantiate(BMessage *data); - virtual status_t Archive(BMessage *data, bool deep = true) const; - - virtual void MouseDown(BPoint point); - virtual void MouseUp(BPoint point); - - virtual void Draw(BRect updateRect); - - private: - void Init(); - - private: - StatusWindow *fWindow; - ppp_interface_id fID; - int32 fLastButtons; -}; - - -#endif diff --git a/src/bin/ppp_up/PPPUpAddon.cpp b/src/bin/ppp_up/PPPUpAddon.cpp deleted file mode 100644 index bee8c3d190..0000000000 --- a/src/bin/ppp_up/PPPUpAddon.cpp +++ /dev/null @@ -1,307 +0,0 @@ -/* - * Copyright 2003-2004, Waldemar Kornewald - * Distributed under the terms of the MIT License. - */ - -#include "ConnectionView.h" - -#include "InterfaceUtils.h" -#include "MessageDriverSettingsUtils.h" -#include "settings_tools.h" - -#include -#include -#include -#include -#include -#include - -#include - - -PPPUpAddon::PPPUpAddon(BMessage *addons, ConnectionView *connectionView) - : DialUpAddon(addons), - fAskBeforeConnecting(false), - fHasPassword(false), - fAuthenticatorsCount(0), - fSettings(NULL), - fProfile(NULL), - fConnectionView(connectionView) -{ -} - - -PPPUpAddon::~PPPUpAddon() -{ -} - - -DialUpAddon* -PPPUpAddon::FindDevice(const BString& moduleName) const -{ - DialUpAddon *addon; - for(int32 index = 0; Addons()->FindPointer(DUN_DEVICE_ADDON_TYPE, index, - reinterpret_cast(&addon)) == B_OK; index++) - if(addon && moduleName == addon->KernelModuleName()) - return addon; - - return NULL; -} - - -bool -PPPUpAddon::LoadSettings(BMessage *settings, BMessage *profile, bool isNew) -{ - fIsNew = isNew; - fAskBeforeConnecting = fHasPassword = false; - fDeviceName = fUsername = fPassword = ""; - fDeviceAddon = NULL; - fAuthenticatorsCount = 0; - fSettings = settings; - fProfile = profile; - - fConnectionView->Reload(); - - if(!settings || !profile || isNew) - return true; - - BMessage parameter; - int32 index = 0; - const char *value; - if(FindMessageParameter(PPP_ASK_BEFORE_CONNECTING_KEY, *fSettings, ¶meter, - &index) && parameter.FindString(MDSU_VALUES, &value) == B_OK) { - if(get_boolean_value(value, false)) - fAskBeforeConnecting = true; - - parameter.AddBool(MDSU_VALID, true); - fSettings->ReplaceMessage(MDSU_PARAMETERS, index, ¶meter); - } - - if(!LoadDeviceSettings()) - return false; - - if(!LoadAuthenticationSettings()) - return false; - - fConnectionView->Reload(); - // reload new settings - - return true; -} - - -bool -PPPUpAddon::LoadDeviceSettings() -{ - int32 index = 0; - BMessage device; - if(!FindMessageParameter(PPP_DEVICE_KEY, *fSettings, &device, &index)) - return false; - - if(device.FindString(MDSU_VALUES, &fDeviceName) != B_OK) - return false; - - device.AddBool(MDSU_VALID, true); - fSettings->ReplaceMessage(MDSU_PARAMETERS, index, &device); - - fDeviceAddon = FindDevice(fDeviceName); - if(!fDeviceAddon) - return false; - - return fDeviceAddon->LoadSettings(fSettings, fProfile, false); -} - - -bool -PPPUpAddon::LoadAuthenticationSettings() -{ - // we only handle the profile (although settings could contain different data) - int32 itemIndex = 0; - BMessage authentication, item; - - if(!FindMessageParameter(PPP_AUTHENTICATOR_KEY, *fProfile, &item, &itemIndex)) - return true; - - // find authenticators (though we load all authenticators, we only use one) - BString name; - for(int32 index = 0; item.FindString(MDSU_VALUES, index, &name) == B_OK; index++) { - BMessage authenticator; - if(!GetAuthenticator(name, &authenticator)) - return false; - // fatal error: we do not know how to handle this authenticator - - MarkAuthenticatorAsValid(name); - authentication.AddString(PPP_UP_AUTHENTICATORS, name); - fAuthenticatorName = name; - ++fAuthenticatorsCount; - } - - fSettings->AddMessage(PPP_UP_AUTHENTICATION, &authentication); - - bool hasUsername = false; - // a username must be present - - // load username and password - BMessage parameter; - int32 parameterIndex = 0; - if(FindMessageParameter("User", item, ¶meter, ¶meterIndex) - && parameter.FindString(MDSU_VALUES, &fUsername) == B_OK) { - hasUsername = true; - parameter.AddBool(MDSU_VALID, true); - item.ReplaceMessage(MDSU_PARAMETERS, parameterIndex, ¶meter); - } - - parameterIndex = 0; - if(FindMessageParameter("Password", item, ¶meter, ¶meterIndex) - && parameter.FindString(MDSU_VALUES, &fPassword) == B_OK) { - fHasPassword = true; - parameter.AddBool(MDSU_VALID, true); - item.ReplaceMessage(MDSU_PARAMETERS, parameterIndex, ¶meter); - } - - // tell DUN whether everything is valid - if(hasUsername) - item.AddBool(MDSU_VALID, true); - - fProfile->ReplaceMessage(MDSU_PARAMETERS, itemIndex, &item); - - return true; -} - - -bool -PPPUpAddon::HasTemporaryProfile() const -{ - return fConnectionView->HasTemporaryProfile(); -} - - -void -PPPUpAddon::IsModified(bool *settings, bool *profile) const -{ - if(!fSettings) { - *settings = *profile = false; - return; - } - - bool deviceSettings, authenticationSettings, deviceProfile, authenticationProfile; - - IsDeviceModified(&deviceSettings, &deviceProfile); - IsAuthenticationModified(&authenticationSettings, &authenticationProfile); - - *settings = (deviceSettings || authenticationSettings); - *profile = (deviceProfile || authenticationProfile); -} - - -void -PPPUpAddon::IsDeviceModified(bool *settings, bool *profile) const -{ - fConnectionView->IsDeviceModified(settings, profile); -} - - -void -PPPUpAddon::IsAuthenticationModified(bool *settings, bool *profile) const -{ - // currently we only support selecting one authenticator - *profile = (*settings || fUsername != fConnectionView->Username() - || (fPassword != fConnectionView->Password() && fHasPassword) - || fHasPassword != fConnectionView->DoesSavePassword()); -} - - -bool -PPPUpAddon::SaveSettings(BMessage *settings, BMessage *profile, bool saveTemporary) -{ - if(!fSettings || !settings) - return false; - // TODO: tell user that a device is needed (if we fail because of this) - - if(!DeviceAddon()->SaveSettings(settings, profile, saveTemporary)) - return false; - - if(CountAuthenticators() > 0) { - BMessage authenticator; - authenticator.AddString(MDSU_NAME, PPP_AUTHENTICATOR_KEY); - authenticator.AddString(MDSU_VALUES, AuthenticatorName()); - settings->AddMessage(MDSU_PARAMETERS, &authenticator); - - BMessage username; - username.AddString(MDSU_NAME, "User"); - username.AddString(MDSU_VALUES, fConnectionView->Username()); - authenticator.AddMessage(MDSU_PARAMETERS, &username); - - if(saveTemporary || fConnectionView->DoesSavePassword()) { - // save password, too - BMessage password; - password.AddString(MDSU_NAME, "Password"); - password.AddString(MDSU_VALUES, fConnectionView->Password()); - authenticator.AddMessage(MDSU_PARAMETERS, &password); - } - - profile->AddMessage(MDSU_PARAMETERS, &authenticator); - } - - return true; -} - - -bool -PPPUpAddon::GetPreferredSize(float *width, float *height) const -{ - // this method is not used, just set values - if(width) - *width = 200; - if(height) - *height = 300; - - return true; -} - - -BView* -PPPUpAddon::CreateView(BPoint leftTop) -{ - return NULL; - // ConnectionView is responsible for our UI -} - - -bool -PPPUpAddon::GetAuthenticator(const BString& moduleName, BMessage *entry) const -{ - if(!entry) - return false; - - BString name; - for(int32 index = 0; Addons()->FindMessage(DUN_AUTHENTICATOR_ADDON_TYPE, index, - entry) == B_OK; index++) { - entry->FindString("KernelModuleName", &name); - if(name == moduleName) - return true; - } - - return false; -} - - -bool -PPPUpAddon::MarkAuthenticatorAsValid(const BString& moduleName) -{ - BMessage authenticator; - int32 index = 0; - BString name; - - for(; FindMessageParameter(PPP_AUTHENTICATOR_KEY, *fSettings, &authenticator, - &index); index++) { - authenticator.FindString("KernelModuleName", &name); - if(name == moduleName) { - authenticator.AddBool(MDSU_VALID, true); - fSettings->ReplaceMessage(MDSU_PARAMETERS, index, &authenticator); - return true; - } - } - - return false; -} diff --git a/src/bin/ppp_up/PPPUpAddon.h b/src/bin/ppp_up/PPPUpAddon.h deleted file mode 100644 index 22c12432a0..0000000000 --- a/src/bin/ppp_up/PPPUpAddon.h +++ /dev/null @@ -1,86 +0,0 @@ -/* - * Copyright 2003-2004, Waldemar Kornewald - * Distributed under the terms of the MIT License. - */ - -#ifndef PPP_UP_ADDON__H -#define PPP_UP_ADDON__H - -#include - -#include -#include -#include - -class ConnectionView; - -// string constants for information saved in the settings message -#define PPP_UP_AUTHENTICATION "Authentication" -#define PPP_UP_AUTHENTICATORS "Authenticators" - - -class PPPUpAddon : public DialUpAddon { - public: - PPPUpAddon(BMessage *addons, ConnectionView *connectionView); - virtual ~PPPUpAddon(); - - bool IsNew() const - { return fIsNew; } - bool AskBeforeConnecting() const - { return fAskBeforeConnecting; } - - const char *DeviceName() const - { return fDeviceName.String(); } - const char *AuthenticatorName() const - { return fAuthenticatorName.String(); } - const char *Username() const - { return fUsername.String(); } - const char *Password() const - { return fPassword.String(); } - bool HasPassword() const - { return fHasPassword; } - - DialUpAddon *FindDevice(const BString& moduleName) const; - DialUpAddon *DeviceAddon() const - { return fDeviceAddon; } - - int32 CountAuthenticators() const - { return fAuthenticatorsCount; } - - BMessage *Settings() const - { return fSettings; } - BMessage *Profile() const - { return fProfile; } - - virtual int32 Position() const - { return 0; } - virtual bool LoadSettings(BMessage *settings, BMessage *profile, bool isNew); - bool LoadDeviceSettings(); - bool LoadAuthenticationSettings(); - - virtual bool HasTemporaryProfile() const; - virtual void IsModified(bool *settings, bool *profile) const; - void IsDeviceModified(bool *settings, bool *profile) const; - void IsAuthenticationModified(bool *settings, bool *profile) const; - - virtual bool SaveSettings(BMessage *settings, BMessage *profile, - bool saveTemporary); - virtual bool GetPreferredSize(float *width, float *height) const; - virtual BView *CreateView(BPoint leftTop); - - private: - bool GetAuthenticator(const BString& moduleName, BMessage *entry) const; - bool MarkAuthenticatorAsValid(const BString& moduleName); - - private: - bool fIsNew, fAskBeforeConnecting, fHasPassword; - BString fDeviceName, fAuthenticatorName, fUsername, fPassword; - DialUpAddon *fDeviceAddon; - int32 fAuthenticatorsCount; - BMessage *fSettings, *fProfile; - // saves last settings state - ConnectionView *fConnectionView; -}; - - -#endif diff --git a/src/bin/ppp_up/PPPUpApplication.cpp b/src/bin/ppp_up/PPPUpApplication.cpp deleted file mode 100644 index 6bc32becb2..0000000000 --- a/src/bin/ppp_up/PPPUpApplication.cpp +++ /dev/null @@ -1,132 +0,0 @@ -/* - * Copyright 2004-2005, Waldemar Kornewald - * Distributed under the terms of the MIT License. - */ - -#include "PPPUpApplication.h" - -#include - -#include "DialUpView.h" -#include "ConnectionWindow.h" -#include -#include - -#include -#include "PPPDeskbarReplicant.h" - - -static -status_t -report_thread(void *data) -{ - PPPUpApplication *app = static_cast(data); - - // Send reply. From now on we will receive report messages. - send_data(app->ReplyThread(), 0, NULL, 0); - - // get messages and open connection window when we receive a GOING_UP report - thread_id sender, me = find_thread(NULL); - int32 reportCode; - ppp_interface_id id; - ppp_report_packet report; - ConnectionWindow *window = NULL; - while(true) { - reportCode = receive_data(&sender, &report, sizeof(report)); - if(reportCode == PPP_RESPONSE_TEST_CODE) { - if(!window || window->ResponseTest()) - PPP_REPLY(sender, B_OK); - else - PPP_REPLY(sender, B_ERROR); - continue; - } else if(reportCode != PPP_REPORT_CODE) - continue; - - if(report.type == PPP_DESTRUCTION_REPORT) { - id = PPP_UNDEFINED_INTERFACE_ID; - PPP_REPLY(sender, B_OK); - } else if(report.type != PPP_CONNECTION_REPORT) { - PPP_REPLY(sender, B_OK); - continue; - } else if(report.length == sizeof(ppp_interface_id)) - memcpy(&id, report.data, sizeof(ppp_interface_id)); - else - id = PPP_UNDEFINED_INTERFACE_ID; - - // notify window - if(window && (report.type == PPP_DESTRUCTION_REPORT - || report.type == PPP_CONNECTION_REPORT)) { - BMessage message; - message.AddInt32("code", report.type == PPP_DESTRUCTION_REPORT - ? PPP_REPORT_DOWN_SUCCESSFUL : report.code); - message.AddInt32("interface", id); - window->UpdateStatus(message); - } - - if(report.code == PPP_REPORT_GOING_UP) { - // create connection window (it will send the reply for us) (DONE?) - BRect rect(150, 50, 450, 435); - if(!window) { - window = new ConnectionWindow(rect, app->Name(), app->ID(), me); - window->Show(); - } - - window->RequestReply(); - // wait for reply from window and forward it to the kernel - thread_id tmp; - PPP_REPLY(sender, receive_data(&tmp, NULL, 0)); - } else { - if(report.code == PPP_REPORT_UP_SUCCESSFUL) { - // add deskbar replicant (DONE?) - PPPDeskbarReplicant *replicant = new PPPDeskbarReplicant(id); - BDeskbar().AddItem(replicant); - delete replicant; - } - - PPP_REPLY(sender, PPP_OK_DISABLE_REPORTS); - } - } - - return B_OK; -} - - -int -main(int argc, const char *argv[]) -{ - if(argc != 2) - return -1; - - const char *name = argv[1]; - - thread_id replyThread; - ppp_interface_id id; - receive_data(&replyThread, &id, sizeof(id)); - - new PPPUpApplication(name, id, replyThread); - be_app->Run(); - delete be_app; - - return 0; -} - - -PPPUpApplication::PPPUpApplication(const char *name, ppp_interface_id id, - thread_id replyThread) - : BApplication(APP_SIGNATURE), - fName(name), - fID(id), - fReplyThread(replyThread) -{ -} - - -void -PPPUpApplication::ReadyToRun() -{ - // Create report message thread (which in turn sends the reply and creates - // the connection window). (DONE?) - thread_id reportThread = spawn_thread(report_thread, "ppp_up: report_thread", - B_NORMAL_PRIORITY, this); - resume_thread(reportThread); -} diff --git a/src/bin/ppp_up/PPPUpApplication.h b/src/bin/ppp_up/PPPUpApplication.h deleted file mode 100644 index 601a851d9e..0000000000 --- a/src/bin/ppp_up/PPPUpApplication.h +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright 2005, Waldemar Kornewald - * Distributed under the terms of the MIT License. - */ - -#ifndef PPP_UP_APPLICATION__H -#define PPP_UP_APPLICATION__H - -#include -#include - -class ConnectionWindow; - -#define APP_SIGNATURE "application/x-vnd.haiku.ppp_up" - - -class PPPUpApplication : public BApplication { - public: - PPPUpApplication(const char *name, ppp_interface_id id, - thread_id replyThread); - - virtual void ReadyToRun(); - - const char *Name() const - { return fName; } - ppp_interface_id ID() const - { return fID; } - thread_id ReplyThread() const - { return fReplyThread; } - - private: - const char *fName; - ppp_interface_id fID; - thread_id fReplyThread; - ConnectionWindow *fWindow; -}; - - -#endif diff --git a/src/bin/ppp_up/README b/src/bin/ppp_up/README deleted file mode 100644 index c87a36eab6..0000000000 --- a/src/bin/ppp_up/README +++ /dev/null @@ -1,7 +0,0 @@ -Usage: -ppp_up INTERFACENAME - -The app waits until it receives a thread message containing the interface id. The sender of this message will wait for a reply that indicates that ppp_up is ready to run. The replying thread will be registered as a report message receiver (no reply timeout). -If the interface is configured to ask the user before connecting or if the password is missing although a login is needed, ppp_up will open a request window and wait for the user to enter the login information. All changes will be saved. Actually, the login view that is presented to the user is the same as the one used in the "Internet" settings (including its behaviour). - -If a connection could be established ppp_up will add a connection status replicant to the Deskbar. diff --git a/src/bin/ppp_up/StatusView.cpp b/src/bin/ppp_up/StatusView.cpp deleted file mode 100644 index b61f4f4460..0000000000 --- a/src/bin/ppp_up/StatusView.cpp +++ /dev/null @@ -1,176 +0,0 @@ -/* - * Copyright 2005, Waldemar Kornewald - * Distributed under the terms of the MIT License. - */ - -#include "StatusView.h" - -#include -#include -#include -#include - -#include -#include - -#include - - -// message constants -static const uint32 kMsgDisconnect = 'DISC'; - -// labels -static const char *kLabelDisconnect = "Disconnect"; -static const char *kLabelConnectedSince = "Connected Since: "; -static const char *kLabelReceived = "Received"; -static const char *kLabelSent = "Sent"; - -// strings -static const char *kTextBytes = "Bytes"; -static const char *kTextPackets = "Packets"; - - -StatusView::StatusView(BRect rect, ppp_interface_id id) - : BView(rect, "StatusView", B_FOLLOW_NONE, B_PULSE_NEEDED), - fInterface(id) -{ - SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR)); - - rect = Bounds(); - rect.InsetBy(5, 5); - rect.left = rect.right - 80; - rect.bottom = rect.top + 25; - fButton = new BButton(rect, "DisconnectButton", kLabelDisconnect, - new BMessage(kMsgDisconnect)); - - rect.right = rect.left - 10; - rect.left = rect.right - 80; - rect.top += 5; - rect.bottom = rect.top + 15; - fTime = new BStringView(rect, "Time", ""); - fTime->SetAlignment(B_ALIGN_RIGHT); - fTime->SetFont(be_fixed_font); - rect.right = rect.left - 10; - rect.left = 5; - BStringView *connectedSince = new BStringView(rect, "ConnectedSince", - kLabelConnectedSince); - connectedSince->SetFont(be_fixed_font); - - rect = Bounds(); - rect.InsetBy(5, 5); - rect.top += 35; - rect.right = rect.left + (rect.Width() - 5) / 2; - BBox *received = new BBox(rect, "Received"); - received->SetLabel(kLabelReceived); - rect = received->Bounds(); - rect.InsetBy(10, 15); - rect.bottom = rect.top + 15; - fBytesReceived = new BStringView(rect, "BytesReceived", ""); - fBytesReceived->SetAlignment(B_ALIGN_RIGHT); - fBytesReceived->SetFont(be_fixed_font); - rect.top = rect.bottom + 5; - rect.bottom = rect.top + 15; - fPacketsReceived = new BStringView(rect, "PacketsReceived", ""); - fPacketsReceived->SetAlignment(B_ALIGN_RIGHT); - fPacketsReceived->SetFont(be_fixed_font); - - rect = received->Frame(); - rect.OffsetBy(rect.Width() + 5, 0); - BBox *sent = new BBox(rect, "sent"); - sent->SetLabel(kLabelSent); - rect = received->Bounds(); - rect.InsetBy(10, 15); - rect.bottom = rect.top + 15; - fBytesSent = new BStringView(rect, "BytesSent", ""); - fBytesSent->SetAlignment(B_ALIGN_RIGHT); - fBytesSent->SetFont(be_fixed_font); - rect.top = rect.bottom + 5; - rect.bottom = rect.top + 15; - fPacketsSent = new BStringView(rect, "PacketsSent", ""); - fPacketsSent->SetAlignment(B_ALIGN_RIGHT); - fPacketsSent->SetFont(be_fixed_font); - - received->AddChild(fBytesReceived); - received->AddChild(fPacketsReceived); - sent->AddChild(fBytesSent); - sent->AddChild(fPacketsSent); - - AddChild(fButton); - AddChild(fTime); - AddChild(connectedSince); - AddChild(received); - AddChild(sent); - - ppp_interface_info_t info; - fInterface.GetInterfaceInfo(&info); - fConnectedSince = info.info.connectedSince; -} - - -void -StatusView::AttachedToWindow() -{ - fButton->SetTarget(this); - Window()->SetTitle(fInterface.Name()); -} - - -void -StatusView::MessageReceived(BMessage *message) -{ - switch(message->what) { - case kMsgDisconnect: - fInterface.Down(); - Window()->Hide(); - break; - - default: - BView::MessageReceived(message); - } -} - - -void -StatusView::Pulse() -{ - // update status - ppp_statistics statistics; - if(!fInterface.GetStatistics(&statistics)) { - fBytesReceived->SetText(""); - fPacketsReceived->SetText(""); - fBytesSent->SetText(""); - fPacketsSent->SetText(""); - return; - } - - BString text; - bigtime_t time = system_time() - fConnectedSince; - time /= 1000000; - int32 seconds = time % 60; - time /= 60; - int32 minutes = time % 60; - int32 hours = time / 60; - char minsec[7]; - if(hours) { - sprintf(minsec, ":%02ld:%02ld", minutes, seconds); - text << hours << minsec; - } else if(minutes) { - sprintf(minsec, "%ld:%02ld", minutes, seconds); - text << minsec; - } else - text << seconds; - fTime->SetText(text.String()); - - text = ""; - text << statistics.bytesReceived << ' ' << kTextBytes; - fBytesReceived->SetText(text.String()); - text = ""; - text << statistics.packetsReceived << ' ' << kTextPackets; - fPacketsReceived->SetText(text.String()); - text = ""; - text << statistics.bytesSent << ' ' << kTextBytes; - fBytesSent->SetText(text.String()); - text = ""; - text << statistics.packetsSent << ' ' << kTextPackets; - fPacketsSent->SetText(text.String()); -} diff --git a/src/bin/ppp_up/StatusView.h b/src/bin/ppp_up/StatusView.h deleted file mode 100644 index 1808ac8edc..0000000000 --- a/src/bin/ppp_up/StatusView.h +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Copyright 2005, Waldemar Kornewald - * Distributed under the terms of the MIT License. - */ - -#ifndef STATUS_VIEW__H -#define STATUS_VIEW__H - -#include -#include - - -class StatusView : public BView { - public: - StatusView(BRect rect, ppp_interface_id id); - - virtual void AttachedToWindow(); - virtual void MessageReceived(BMessage *message); - virtual void Pulse(); - - private: - BButton *fButton; - BStringView *fTime; - BStringView *fBytesReceived, *fBytesSent, *fPacketsReceived, *fPacketsSent; - bigtime_t fConnectedSince; - PPPInterface fInterface; -}; - - -#endif diff --git a/src/bin/ppp_up/StatusWindow.cpp b/src/bin/ppp_up/StatusWindow.cpp deleted file mode 100644 index f335bc2949..0000000000 --- a/src/bin/ppp_up/StatusWindow.cpp +++ /dev/null @@ -1,27 +0,0 @@ -/* - * Copyright 2005, Waldemar Kornewald - * Distributed under the terms of the MIT License. - */ - -#include "StatusWindow.h" -#include "StatusView.h" - - -StatusWindow::StatusWindow(BRect frame, ppp_interface_id id) - : BWindow(frame, "", B_TITLED_WINDOW, B_NOT_RESIZABLE | B_NOT_ZOOMABLE, - B_ALL_WORKSPACES) -{ - SetPulseRate(1000000); - - StatusView *view = new StatusView(Bounds(), id); - AddChild(view); -} - - -bool -StatusWindow::QuitRequested() -{ - // only the replicant may delete this window! - Hide(); - return false; -} diff --git a/src/bin/ppp_up/StatusWindow.h b/src/bin/ppp_up/StatusWindow.h deleted file mode 100644 index 41d9eb1d1a..0000000000 --- a/src/bin/ppp_up/StatusWindow.h +++ /dev/null @@ -1,21 +0,0 @@ -/* - * Copyright 2005, Waldemar Kornewald - * Distributed under the terms of the MIT License. - */ - -#ifndef STATUS_WINDOW__H -#define STATUS_WINDOW__H - -#include -#include - - -class StatusWindow : public BWindow { - public: - StatusWindow(BRect frame, ppp_interface_id id); - - virtual bool QuitRequested(); -}; - - -#endif diff --git a/src/bin/ppp_up/TODO b/src/bin/ppp_up/TODO deleted file mode 100644 index 565ea98c80..0000000000 --- a/src/bin/ppp_up/TODO +++ /dev/null @@ -1,6 +0,0 @@ -Add Deskbar replicant. - -I hope it is not too annoying that the user cannot select an alternative interface for connecting. The problem lies in the stack's concept that everything is an add-on. We cannot know if the connection-initiating packet type is supported by the alternative interface (or, we could, but we would have to load (and write) many add-ons that understand how the stack modules work). -This problem is minimised by showing the device view which allows changing the phone number for modems, for example. - -Add some indicator to the add-ons message that says we are ppp_up, not the preflet. diff --git a/src/bin/ppp_up/ppp_up.rdef b/src/bin/ppp_up/ppp_up.rdef deleted file mode 100644 index 61654e33c8..0000000000 --- a/src/bin/ppp_up/ppp_up.rdef +++ /dev/null @@ -1,37 +0,0 @@ -/* - ppp_up.rdef -*/ - -resource app_signature "application/x-vnd.haiku.ppp_up"; - -/* BEOS:APP_FLAGS : - 00000000 = SINGLE LAUNCH - 00000001 = MULTIPLE LAUNCH - 00000002 = EXCLUSIVE LAUNCH - 00000004 = BACKGROUND APP + SINGLE LAUNCH - 00000005 = BACKGROUND APP + MULTIPLE LAUNCH - 00000006 = BACKGROUND APP + EXCLUSIVE LAUNCH - 00000008 = ARGV_ONLY + SINGLE LAUNCH - 00000009 = ARGV_ONLY + MULTIPLE LAUNCH - 0000000A = ARGV_ONLY + EXCLUSIVE LAUNCH - 0000000C = ARGV_ONLY + BACKGROUND APP + SINGLE LAUNCH - 0000000D = ARGV_ONLY + BACKGROUND APP + MULTIPLE LAUNCH - 0000000E = ARGV_ONLY + BACKGROUND APP + EXCLUSIVE LAUNCH -*/ - -resource app_flags 0x00000005; - -resource app_version { - major = 0, - middle = 1, - minor = 0, - - /* 0 = development 1 = alpha 2 = beta - 3 = gamma 4 = golden master 5 = final */ - variety = 0, - - internal = 0, - - short_info = "ppp_up", - long_info = "PPP interface GUI initialization app." -}; diff --git a/src/servers/Jamfile b/src/servers/Jamfile index acfc053449..28889bb05e 100644 --- a/src/servers/Jamfile +++ b/src/servers/Jamfile @@ -7,7 +7,7 @@ SubInclude OBOS_TOP src servers mail ; SubInclude OBOS_TOP src servers media ; SubInclude OBOS_TOP src servers media_addon ; SubInclude OBOS_TOP src servers midi ; -# SubInclude OBOS_TOP src servers net ; +SubInclude OBOS_TOP src servers net ; SubInclude OBOS_TOP src servers power ; SubInclude OBOS_TOP src servers print ; SubInclude OBOS_TOP src servers registrar ; diff --git a/src/servers/net/Jamfile b/src/servers/net/Jamfile index e746628d22..5ced1ca9a0 100644 --- a/src/servers/net/Jamfile +++ b/src/servers/net/Jamfile @@ -17,10 +17,6 @@ Server net_server : # built-in add-ons PPPServer.cpp - - # old net_server (was a netstack tester app) -# userland_server.c -# userland_ipc.c ; LinkSharedOSLibs net_server : @@ -29,6 +25,5 @@ LinkSharedOSLibs net_server : libbind.so # for PPP - libdunview.a libppp.a ; diff --git a/src/servers/net/NetServer.cpp b/src/servers/net/NetServer.cpp index cfc7c2c58a..a8e6d87d27 100644 --- a/src/servers/net/NetServer.cpp +++ b/src/servers/net/NetServer.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2004, Waldemar Kornewald + * Copyright 2004-2005, Waldemar Kornewald * Distributed under the terms of the MIT License. */ diff --git a/src/servers/net/PPPServer.cpp b/src/servers/net/PPPServer.cpp index 61641e457e..423e59d2a1 100644 --- a/src/servers/net/PPPServer.cpp +++ b/src/servers/net/PPPServer.cpp @@ -1,28 +1,19 @@ /* - * Copyright 2004, Waldemar Kornewald + * Copyright 2004-2005, Waldemar Kornewald * Distributed under the terms of the MIT License. */ #include "PPPServer.h" -#include "SimpleMessageFilter.h" #include -// the message constants that should be filtered -static const uint32 *kPPPWhatValues = { - // PPPS_CONNECT, - 0 // end-of-list -}; - - PPPServer::PPPServer() - : BHandler("PPPServer") + : BHandler("PPPServer"), + fListener(this) { be_app->AddHandler(this); - fFilter = new SimpleMessageFilter(kPPPWhatValues, this); - be_app->AddCommonFilter(fFilter); - fListener = new PPPInterfaceListener(this); - fListener->WatchAllInterfaces(); + + fListener.WatchManager(); InitInterfaces(); } @@ -30,10 +21,11 @@ PPPServer::PPPServer() PPPServer::~PPPServer() { - delete fListener; - be_app->RemoveCommonFilter(fFilter); + UninitInterfaces(); + + fListener.StopWatchingManager(); + be_app->RemoveHandler(this); - delete fFilter; } @@ -54,53 +46,36 @@ PPPServer::MessageReceived(BMessage *message) void PPPServer::InitInterfaces() { + // TODO: create one ConnectionRequestWindow per interface } -bool -PPPServer::AskBeforeDialing(ppp_interface_id id) +void +PPPServer::UninitInterfaces() { - return false; + // TODO: delete all ConnectionRequestWindows } void PPPServer::HandleReportMessage(BMessage *message) { - thread_id sender; - message->FindInt32("sender", &sender); - ppp_interface_id id; - if(message->FindInt32("interface", reinterpret_cast(&id)) != B_OK) { - send_data(sender, B_OK, NULL, 0); + if(message->FindInt32("interface", reinterpret_cast(&id)) != B_OK) return; - } int32 type, code; message->FindInt32("type", &type); message->FindInt32("code", &code); - if(type == PPP_MANAGER_REPORT && code == PPP_REPORT_INTERFACE_CREATED) { - // TODO: check if we need to add this interface to our watch-list - } else if(type == PPP_CONNECTION_REPORT) { - switch(code) { - case PPP_REPORT_GOING_UP: { - if(AskBeforeDialing(id)) { - OpenDialRequestWindow(id, sender); - return; - } - } break; - } - } else if(type == PPP_DESTRUCTION_REPORT) { - // TODO: check if this interface has DOD enabled. if so: create new! - } - - send_data(sender, B_OK, NULL, 0); + if(type == PPP_MANAGER_REPORT && code == PPP_REPORT_INTERFACE_CREATED) + CreateConnectionRequestWindow(id); } void -PPPServer::OpenDialRequestWindow(ppp_interface_id id, thread_id sender) +PPPServer::CreateConnectionRequestWindow(ppp_interface_id id) { - + // TODO: create window, register window as report receiver for the interface + // XXX: if a window for that ID exists then only register it as report receiver } diff --git a/src/servers/net/PPPServer.h b/src/servers/net/PPPServer.h index 5ae3beaf09..d2b2f7f577 100644 --- a/src/servers/net/PPPServer.h +++ b/src/servers/net/PPPServer.h @@ -1,5 +1,5 @@ /* - * Copyright 2004, Waldemar Kornewald + * Copyright 2004-2005, Waldemar Kornewald * Distributed under the terms of the MIT License. */ @@ -9,8 +9,6 @@ #include #include -class SimpleMessageFilter; - class PPPServer : public BHandler { public: @@ -22,14 +20,13 @@ class PPPServer : public BHandler { private: void InitInterfaces(); - bool AskBeforeDialing(ppp_interface_id id); + void UninitInterfaces(); void HandleReportMessage(BMessage *message); - void OpenDialRequestWindow(ppp_interface_id id, thread_id sender); + void CreateConnectionRequestWindow(ppp_interface_id id); private: - SimpleMessageFilter *fFilter; - PPPInterfaceListener *fListener; + PPPInterfaceListener fListener; }; diff --git a/src/servers/net/userland_ipc.c b/src/servers/net/userland_ipc.c deleted file mode 100644 index 2253a0ffec..0000000000 --- a/src/servers/net/userland_ipc.c +++ /dev/null @@ -1,554 +0,0 @@ -/* userland_ipc - Communication between the network driver -** and the userland stack. -** -** Initial version by Axel Dörfler, axeld@pinc-software.de -** This file may be used under the terms of the OpenBeOS License. -*/ - - -#include "userland_ipc.h" - -#include "sys/socket.h" -#include "net_misc.h" -#include "core_module.h" -#include "net_module.h" -#include "sys/sockio.h" - -#include -#include -#include - - -extern struct core_module_info *core; - -// installs a main() -//#define COMMUNICATION_TEST - -#define NUM_COMMANDS 32 -#define CONNECTION_BUFFER_SIZE (65536 + 4096 - CONNECTION_COMMAND_SIZE) - -#define ROUND_TO_PAGE_SIZE(x) (((x) + (B_PAGE_SIZE) - 1) & ~((B_PAGE_SIZE) - 1)) - -struct socket; /* forward declaration */ - -typedef struct { - port_id localPort,port; - area_id area; - struct socket * socket; - - uint8 *buffer; - net_command *commands; - sem_id commandSemaphore; - - int32 openFlags; - - thread_id runner; - - // for socket select events support - port_id socket_event_port; - void * notify_cookie; -} connection_cookie; - - -port_id gStackPort = -1; -thread_id gConnectionOpener = -1; - -// prototypes -static int32 connection_runner(void *_cookie); -static status_t init_connection(net_connection *connection, connection_cookie **_cookie); -static void shutdown_connection(connection_cookie *cookie); - - -static void -delete_cloned_areas(net_area_info *area) -{ - int32 i; - for (i = 0;i < MAX_NET_AREAS;i++) { - if (area[i].id == 0) - continue; - - delete_area(area[i].id); - } -} - - -static status_t -clone_command_areas(net_area_info *localArea,net_command *command) -{ - int32 i; - - memset(localArea,0,sizeof(net_area_info) * MAX_NET_AREAS); - - for (i = 0;i < MAX_NET_AREAS;i++) { - if (command->area[i].id <= 0) - continue; - - localArea[i].id = clone_area("net connection",(void **)&localArea[i].offset,B_ANY_ADDRESS, - B_READ_AREA | B_WRITE_AREA,command->area[i].id); - if (localArea[i].id < B_OK) - return localArea[i].id; - } - return B_OK; -} - - -static uint8 * -convert_address(net_area_info *fromArea,net_area_info *toArea,uint8 *data) -{ - if (data == NULL) - return NULL; - - if (data < fromArea->offset) { - printf("could not translate address: %p\n",data); - return data; - } - - return data - fromArea->offset + toArea->offset; -} - - -static inline void * -convert_to_local(net_area_info *foreignArea,net_area_info *localArea,void *data) -{ - return convert_address(foreignArea,localArea,data); -} - - -static void * -convert_to_foreign(net_area_info *foreignArea,net_area_info *localArea,void *data) -{ - return convert_address(localArea,foreignArea,data); -} - - -static void -on_socket_event(void * socket, uint32 event, void * cookie) -{ - connection_cookie * cc = (connection_cookie *) cookie; - struct socket_event_data sed; - status_t status; - - if (!cc) - return; - - if (cc->socket != socket) { - printf("on_socket_event(%p, %ld, %p): socket is higly suspect! Aborting.\n", socket, event, cookie); - return; - } - - printf("on_socket_event(%p, %ld, %p)\n", socket, event, cookie); - - sed.event = event; - sed.cookie = cc->notify_cookie; - - // TODO: don't block here => write_port_etc() ? - status = write_port(cc->socket_event_port, NET_STACK_SOCKET_EVENT_NOTIFICATION, - &sed, sizeof(sed)); - if (status != B_OK) - printf("write_port(NET_STACK_SOCKET_EVENT_NOTIFICATION) failure: %s\n", - strerror(status)); - return; -} - - - -static int32 -connection_runner(void *_cookie) -{ - connection_cookie *cookie = (connection_cookie *)_cookie; - bool run = true; - - while (run) { - net_area_info area[MAX_NET_AREAS]; - net_command *command; - status_t status = B_OK; - uint8 *data; - int32 index; - ssize_t bytes = read_port(cookie->localPort,&index,NULL,0); - if (bytes < B_OK) - break; - - if (index >= NUM_COMMANDS || index < 0) { - printf("got bad command index: %lx\n",index); - continue; - } - command = cookie->commands + index; - if (clone_command_areas(area,command) < B_OK) { - printf("could not clone command areas!\n"); - continue; - } - - data = convert_to_local(&command->area[0],&area[0],command->data); - printf("command %lx (index = %ld), buffer = %p, length = %ld, result = %ld\n",command->op,index,data,command->length,command->result); - - switch (command->op) { - case NET_STACK_OPEN: - { - struct int_args *args = (struct int_args *)data; - cookie->openFlags = args->value; - printf("opening socket, mode = %lx!\n",cookie->openFlags); - break; - } - case NET_STACK_CLOSE: - printf("closing socket...\n"); - run = false; - break; - - case NET_STACK_SOCKET: - { - struct socket_args *args = (struct socket_args *)data; - - printf("open a socket... family = %d, type = %d, proto = %d\n",args->family,args->type,args->proto); - status = core->socket_init(&cookie->socket); - if (status == 0) - status = core->socket_create(cookie->socket, args->family, args->type, args->proto); - break; - } - case NET_STACK_GETSOCKOPT: - case NET_STACK_SETSOCKOPT: - { - struct sockopt_args *sockopt = (struct sockopt_args *)data; - - if (command->op == NET_STACK_GETSOCKOPT) { - status = core->socket_getsockopt(cookie->socket,sockopt->level,sockopt->option, - convert_to_local(&command->area[1],&area[1],sockopt->optval), - (size_t *)&sockopt->optlen); - } else { - status = core->socket_setsockopt(cookie->socket,sockopt->level,sockopt->option, - (const void *)convert_to_local(&command->area[1],&area[1],sockopt->optval), - sockopt->optlen); - } - break; - } - case NET_STACK_CONNECT: - case NET_STACK_BIND: - case NET_STACK_GETSOCKNAME: - case NET_STACK_GETPEERNAME: - { - struct sockaddr_args *args = (struct sockaddr_args *)data; - caddr_t addr = (caddr_t)convert_to_local(&command->area[1],&area[1],args->addr); - - switch (command->op) { - case NET_STACK_CONNECT: - status = core->socket_connect(cookie->socket,addr,args->addrlen); - break; - case NET_STACK_BIND: - status = core->socket_bind(cookie->socket,addr,args->addrlen); - break; - case NET_STACK_GETSOCKNAME: - status = core->socket_getsockname(cookie->socket,(struct sockaddr *)addr,&args->addrlen); - break; - case NET_STACK_GETPEERNAME: - status = core->socket_getpeername(cookie->socket,(struct sockaddr *)addr,&args->addrlen); - break; - } - break; - } - case NET_STACK_LISTEN: - status = core->socket_listen(cookie->socket,((struct int_args *)data)->value); - break; - - case NET_STACK_GET_COOKIE: - /* this is needed by accept() call, to be able to pass back - * in NET_STACK_ACCEPT opcode the cookie of the filedescriptor to - * use for the new accepted socket - */ - *((void **)data) = cookie; - break; - - case NET_STACK_ACCEPT: - { - struct accept_args *args = (struct accept_args *)data; - connection_cookie *otherCookie = (connection_cookie *)args->cookie; - status = core->socket_accept(cookie->socket,&otherCookie->socket, - convert_to_local(&command->area[1],&area[1],args->addr), - &args->addrlen); - } - case NET_STACK_SEND: - { - struct data_xfer_args *args = (struct data_xfer_args *)data; - struct iovec iov; - int flags = 0; - - iov.iov_base = convert_to_local(&command->area[1],&area[1],args->data); - iov.iov_len = args->datalen; - - status = core->socket_writev(cookie->socket,&iov,flags); - break; - } - case NET_STACK_RECV: - { - struct data_xfer_args *args = (struct data_xfer_args *)data; - struct iovec iov; - int flags = 0; - - iov.iov_base = convert_to_local(&command->area[1],&area[1],args->data); - iov.iov_len = args->datalen; - - /* flags gets ignored here... */ - status = core->socket_readv(cookie->socket,&iov,&flags); - break; - } - case NET_STACK_RECVFROM: - { - struct msghdr *msg = (struct msghdr *)data; - int received; - - msg->msg_name = convert_to_local(&command->area[1],&area[1],msg->msg_name); - msg->msg_iov = convert_to_local(&command->area[2],&area[2],msg->msg_iov); - msg->msg_control = convert_to_local(&command->area[3],&area[3],msg->msg_control); - - status = core->socket_recv(cookie->socket, msg, (caddr_t)&msg->msg_namelen,&received); - if (status == 0) - status = received; - - msg->msg_name = convert_to_foreign(&command->area[1],&area[1],msg->msg_name); - msg->msg_iov = convert_to_foreign(&command->area[2],&area[2],msg->msg_iov); - msg->msg_control = convert_to_foreign(&command->area[3],&area[3],msg->msg_control); - break; - } - case NET_STACK_SENDTO: - { - struct msghdr *msg = (struct msghdr *)data; - int sent; - - msg->msg_name = convert_to_local(&command->area[1],&area[1],msg->msg_name); - msg->msg_iov = convert_to_local(&command->area[2],&area[2],msg->msg_iov); - msg->msg_control = convert_to_local(&command->area[3],&area[3],msg->msg_control); - - status = core->socket_send(cookie->socket,msg,msg->msg_flags,&sent); - if (status == 0) - status = sent; - - msg->msg_name = convert_to_foreign(&command->area[1],&area[1],msg->msg_name); - msg->msg_iov = convert_to_foreign(&command->area[2],&area[2],msg->msg_iov); - msg->msg_control = convert_to_foreign(&command->area[3],&area[3],msg->msg_control); - break; - } - - case NET_STACK_NOTIFY_SOCKET_EVENT: - { - struct notify_socket_event_args *args = (struct notify_socket_event_args *)data; - - cookie->socket_event_port = args->notify_port; - cookie->notify_cookie = args->cookie; - - if (cookie->socket_event_port != -1) - // start notify socket event - status = core->socket_set_event_callback(cookie->socket, on_socket_event, cookie, 0); - else - // stop notify socket event - status = core->socket_set_event_callback(cookie->socket, NULL, NULL, 0); - break; - } - - case NET_STACK_SYSCTL: - { - struct sysctl_args *args = (struct sysctl_args *)data; - - status = core->net_sysctl(convert_to_local(&command->area[1],&area[1],args->name), - args->namelen,convert_to_local(&command->area[2],&area[2],args->oldp), - convert_to_local(&command->area[3],&area[3],args->oldlenp), - convert_to_local(&command->area[4],&area[4],args->newp), - args->newlen); - break; - } - - case NET_STACK_STOP: - core->stop(); - break; - - case B_SET_BLOCKING_IO: - cookie->openFlags &= ~O_NONBLOCK; - break; - - case B_SET_NONBLOCKING_IO: - cookie->openFlags |= O_NONBLOCK; - break; - - case OSIOCGIFCONF: - case SIOCGIFCONF: - { - struct ifconf *ifc = (struct ifconf *)data; - ifc->ifc_buf = convert_to_local(&command->area[1],&area[1],ifc->ifc_buf); - - status = core->socket_ioctl(cookie->socket,command->op,(char *)data); - - ifc->ifc_buf = convert_to_foreign(&command->area[1],&area[1],ifc->ifc_buf); - break; - } - - default: - status = core->socket_ioctl(cookie->socket,command->op,(char *)data); - break; - } - // mark the command as done - command->result = status; - command->op = 0; - delete_cloned_areas(area); - - // notify the command pipeline that we're done with the command - release_sem(cookie->commandSemaphore); - } - - cookie->runner = -1; - shutdown_connection(cookie); - - return 0; -} - - -static status_t -init_connection(net_connection *connection,connection_cookie **_cookie) -{ - connection_cookie *cookie; - net_command *commands; - - cookie = (connection_cookie *)malloc(sizeof(connection_cookie)); - if (cookie == NULL) { - fprintf(stderr,"couldn't allocate memory for cookie.\n"); - return B_NO_MEMORY; - } - - connection->area = create_area("net connection",(void *)&commands,B_ANY_ADDRESS, - CONNECTION_BUFFER_SIZE + CONNECTION_COMMAND_SIZE, - B_NO_LOCK,B_READ_AREA | B_WRITE_AREA); - if (connection->area < B_OK) { - fprintf(stderr,"couldn't create area: %s.\n",strerror(connection->area)); - free(cookie); - return connection->area; - } - memset(commands,0,NUM_COMMANDS * sizeof(net_command)); - - connection->port = create_port(CONNECTION_QUEUE_LENGTH,"net stack connection"); - if (connection->port < B_OK) { - fprintf(stderr,"couldn't create port: %s.\n",strerror(connection->port)); - delete_area(connection->area); - free(cookie); - return connection->port; - } - - connection->commandSemaphore = create_sem(0,"net command queue"); - if (connection->commandSemaphore < B_OK) { - fprintf(stderr,"couldn't create semaphore: %s.\n",strerror(connection->commandSemaphore)); - delete_area(connection->area); - delete_port(connection->port); - free(cookie); - return connection->commandSemaphore; - } - - cookie->runner = spawn_thread(connection_runner,"connection runner",B_NORMAL_PRIORITY,cookie); - if (cookie->runner < B_OK) { - fprintf(stderr,"couldn't create thread: %s.\n",strerror(cookie->runner)); - delete_sem(connection->commandSemaphore); - delete_area(connection->area); - delete_port(connection->port); - free(cookie); - return B_ERROR; - } - - connection->numCommands = NUM_COMMANDS; - connection->bufferSize = CONNECTION_BUFFER_SIZE; - - // setup connection cookie - cookie->area = connection->area; - cookie->commands = commands; - cookie->buffer = (uint8 *)commands + CONNECTION_COMMAND_SIZE; - cookie->commandSemaphore = connection->commandSemaphore; - cookie->localPort = connection->port; - cookie->openFlags = 0; - - cookie->socket_event_port = -1; - cookie->notify_cookie = NULL; - - resume_thread(cookie->runner); - - *_cookie = cookie; - return B_OK; -} - - -static void -shutdown_connection(connection_cookie *cookie) -{ - printf("free cookie: %p\n",cookie); - kill_thread(cookie->runner); - - delete_port(cookie->localPort); - delete_sem(cookie->commandSemaphore); - delete_area(cookie->area); - - free(cookie); -} - - -static int32 -connection_opener(void *_unused) -{ - while(true) { - port_id port; - int32 msg; - ssize_t bytes = read_port(gStackPort,&msg,&port,sizeof(port_id)); - if (bytes < B_OK) - return bytes; - - if (msg == NET_STACK_NEW_CONNECTION) { - net_connection connection; - connection_cookie *cookie; - - printf("incoming connection...\n"); - if (init_connection(&connection,&cookie) == B_OK) - write_port(port,NET_STACK_NEW_CONNECTION,&connection,sizeof(net_connection)); - } else - fprintf(stderr,"connection_opener: received unknown command: %lx (expected = %lx)\n",msg,(int32)NET_STACK_NEW_CONNECTION); - } - return 0; -} - - -status_t -init_userland_ipc(void) -{ - gStackPort = create_port(CONNECTION_QUEUE_LENGTH,NET_STACK_PORTNAME); - if (gStackPort < B_OK) - return gStackPort; - - gConnectionOpener = spawn_thread(connection_opener,"connection opener",B_NORMAL_PRIORITY,NULL); - if (resume_thread(gConnectionOpener) < B_OK) { - delete_port(gStackPort); - if (gConnectionOpener >= B_OK) { - kill_thread(gConnectionOpener); - return B_BAD_THREAD_STATE; - } - return gConnectionOpener; - } - - return B_OK; -} - - -void -shutdown_userland_ipc(void) -{ - delete_port(gStackPort); - kill_thread(gConnectionOpener); -} - - -#ifdef COMMUNICATION_TEST -int -main(void) -{ - char buffer[8]; - - if (init_userland_ipc() < B_OK) - return -1; - - puts("Userland_ipc - test is running. Press to quit."); - fgets(buffer,sizeof(buffer),stdin); - - shutdown_userland_ipc(); - - return 0; -} -#endif /* COMMUNICATION_TEST */ diff --git a/src/servers/net/userland_server.c b/src/servers/net/userland_server.c deleted file mode 100644 index 0e9a89a0fd..0000000000 --- a/src/servers/net/userland_server.c +++ /dev/null @@ -1,70 +0,0 @@ -#include "core_funcs.h" -#include "userland_ipc.h" - -#include -#include -#include - - -#define CORE_MODULE_PATH "modules/core" - -struct core_module_info *core = NULL; -static image_id gCoreID; - - -static status_t -load_core(void) -{ - char path[PATH_MAX]; - status_t status = -1; - - getcwd(path, PATH_MAX); - sprintf(path, "%s/%s", path, CORE_MODULE_PATH); - - printf("opening %s\n", path); - gCoreID = load_add_on(path); - if (gCoreID < B_OK) { - fprintf(stderr,"Unable to load the core module: %s\n",strerror(gCoreID)); - return gCoreID; - } - status = get_image_symbol(gCoreID, "core_info",B_SYMBOL_TYPE_ANY,(void**)&core); - if (status < B_OK) { - unload_add_on(gCoreID); - printf("status = %ld, %s\n", status, strerror(status)); - return status; - } - return B_OK; -} - - -static void -unload_core() -{ - core = NULL; - unload_add_on(gCoreID); -} - - -int -main(void) -{ - char buffer[8]; - - if (init_userland_ipc() < B_OK) - return -1; - - if (load_core() < B_OK) { - shutdown_userland_ipc(); - return -1; - } - - core->start(); - - puts("Userland Server - is running. Press to quit."); - fgets(buffer,sizeof(buffer),stdin); - - unload_core(); - shutdown_userland_ipc(); - - return 0; -} diff --git a/src/tests/kits/net/DialUpPreflet/ConnectionOptionsAddon.cpp b/src/tests/kits/net/DialUpPreflet/ConnectionOptionsAddon.cpp index 5e815ad8bd..0996ecb81a 100644 --- a/src/tests/kits/net/DialUpPreflet/ConnectionOptionsAddon.cpp +++ b/src/tests/kits/net/DialUpPreflet/ConnectionOptionsAddon.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2003-2004, Waldemar Kornewald + * Copyright 2003-2005, Waldemar Kornewald * Distributed under the terms of the MIT License. */ @@ -20,21 +20,14 @@ static const uint32 kMsgUpdateControls = 'UCTL'; // labels -#ifdef LANG_GERMAN -static const char *kLabelConnectionOptions = "Optionen"; -static const char *kLabelAskBeforeConnecting = "Vor Dem Verbinden Fragen"; -static const char *kLabelAutoReconnect = "Verbindung Automatisch Wiederherstellen"; -#else static const char *kLabelConnectionOptions = "Options"; static const char *kLabelAskBeforeConnecting = "Ask Before Connecting"; static const char *kLabelAutoReconnect = "Reconnect Automatically"; -#endif ConnectionOptionsAddon::ConnectionOptionsAddon(BMessage *addons) : DialUpAddon(addons), fSettings(NULL), - fProfile(NULL), fConnectionOptionsView(NULL) { CreateView(BPoint(0,0)); @@ -50,17 +43,16 @@ ConnectionOptionsAddon::~ConnectionOptionsAddon() bool -ConnectionOptionsAddon::LoadSettings(BMessage *settings, BMessage *profile, bool isNew) +ConnectionOptionsAddon::LoadSettings(BMessage *settings, bool isNew) { fIsNew = isNew; fAskBeforeConnecting = fDoesAutoReconnect = false; fSettings = settings; - fProfile = profile; fConnectionOptionsView->Reload(); // reset all views (empty settings) - if(!settings || !profile || isNew) + if(!settings || isNew) return true; BMessage parameter; @@ -93,9 +85,9 @@ ConnectionOptionsAddon::LoadSettings(BMessage *settings, BMessage *profile, bool void -ConnectionOptionsAddon::IsModified(bool *settings, bool *profile) const +ConnectionOptionsAddon::IsModified(bool *settings) const { - *settings = *profile = false; + *settings = false; if(!fSettings || !fConnectionOptionsView) return; @@ -106,8 +98,7 @@ ConnectionOptionsAddon::IsModified(bool *settings, bool *profile) const bool -ConnectionOptionsAddon::SaveSettings(BMessage *settings, BMessage *profile, - bool saveTemporary) +ConnectionOptionsAddon::SaveSettings(BMessage *settings) { if(!fSettings || !settings) return false; diff --git a/src/tests/kits/net/DialUpPreflet/ConnectionOptionsAddon.h b/src/tests/kits/net/DialUpPreflet/ConnectionOptionsAddon.h index 60772f7b30..7a20bbd431 100644 --- a/src/tests/kits/net/DialUpPreflet/ConnectionOptionsAddon.h +++ b/src/tests/kits/net/DialUpPreflet/ConnectionOptionsAddon.h @@ -1,5 +1,5 @@ /* - * Copyright 2003-2004, Waldemar Kornewald + * Copyright 2003-2005, Waldemar Kornewald * Distributed under the terms of the MIT License. */ @@ -34,22 +34,19 @@ class ConnectionOptionsAddon : public DialUpAddon { BMessage *Settings() const { return fSettings; } - BMessage *Profile() const - { return fProfile; } virtual int32 Position() const { return 50; } - virtual bool LoadSettings(BMessage *settings, BMessage *profile, bool isNew); - virtual void IsModified(bool *settings, bool *profile) const; - virtual bool SaveSettings(BMessage *settings, BMessage *profile, - bool saveTemporary); + virtual bool LoadSettings(BMessage *settings, bool isNew); + virtual void IsModified(bool *settings) const; + virtual bool SaveSettings(BMessage *settings); virtual bool GetPreferredSize(float *width, float *height) const; virtual BView *CreateView(BPoint leftTop); private: bool fIsNew, fDeleteView; bool fAskBeforeConnecting, fDoesAutoReconnect; - BMessage *fSettings, *fProfile; + BMessage *fSettings; // saves last settings state ConnectionOptionsView *fConnectionOptionsView; }; diff --git a/src/tests/kits/net/DialUpPreflet/DialUpAddon.h b/src/tests/kits/net/DialUpPreflet/DialUpAddon.h index dc187617f0..1ad1144673 100644 --- a/src/tests/kits/net/DialUpPreflet/DialUpAddon.h +++ b/src/tests/kits/net/DialUpPreflet/DialUpAddon.h @@ -1,12 +1,12 @@ /* - * Copyright 2003-2004, Haiku Inc. + * Copyright 2003-2005, Haiku Inc. * Distributed under the terms of the MIT License. */ /*! \class DialUpAddon \brief Base class for DialUpPreflet add-ons. - Connect-Up add-ons must export the following function: \n + DialUp add-ons must export the following function: \n bool register(BMessage *addons) \n You should add your DialUpAddon object to the given BMessage. \n \n @@ -68,32 +68,22 @@ class DialUpAddon { virtual int32 Priority() const { return 0; } - /*! \brief Load the given settings and profile. + /*! \brief Load the given settings. \param isNew Specifies if this is a newly created interface. \return \c true if loading was successful or \c false otherwise. */ - virtual bool LoadSettings(BMessage *settings, BMessage *profile, bool isNew) + virtual bool LoadSettings(BMessage *settings, bool isNew) { return false; } - /*! \brief Returns if this module has a temporary profile. - - A temporary profile is never stored on the hard-disk, but only passed - to the interface on connection. This can include passwords, for example. - */ - virtual bool HasTemporaryProfile() const - { return false; } - //! Are the settings or the profile modified? - virtual void IsModified(bool *settings, bool *profile) const - { *settings = *profile = false; } - /*! \brief Save the given settings and profile. - - \param saveTemporary Specifies if the temporary profile should be written. + //! Are the settings modified? + virtual void IsModified(bool *settings) const + { *settings = false; } + /*! \brief Save the given settings. \return \c true if saving was successful or \c false otherwise. */ - virtual bool SaveSettings(BMessage *settings, BMessage *profile, - bool saveTemporary) + virtual bool SaveSettings(BMessage *settings) { return false; } /*! \brief Get the preferred view size. diff --git a/src/tests/kits/net/DialUpPreflet/DialUpApplication.cpp b/src/tests/kits/net/DialUpPreflet/DialUpApplication.cpp index 0330322907..f2a73d68b2 100644 --- a/src/tests/kits/net/DialUpPreflet/DialUpApplication.cpp +++ b/src/tests/kits/net/DialUpPreflet/DialUpApplication.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2003-2004, Waldemar Kornewald + * Copyright 2003-2004, Waldemar Kornewald * Distributed under the terms of the MIT License. */ diff --git a/src/tests/kits/net/DialUpPreflet/DialUpView.cpp b/src/tests/kits/net/DialUpPreflet/DialUpView.cpp index 86c49b9b6a..f6ecca4a54 100644 --- a/src/tests/kits/net/DialUpPreflet/DialUpView.cpp +++ b/src/tests/kits/net/DialUpPreflet/DialUpView.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2003-2005, Waldemar Kornewald + * Copyright 2003-2005, Waldemar Kornewald * Distributed under the terms of the MIT License. */ @@ -45,17 +45,6 @@ static const uint32 kMsgConnectButton = 'CONI'; static const uint32 kMsgUpdateDefaultInterface = 'UPDT'; // labels -#ifdef LANG_GERMAN -static const char *kLabelInterface = "Verbindung: "; -static const char *kLabelInterfaceName = "Verbindungs-Name: "; -static const char *kLabelCreateNewInterface = "Neue Verbindung Erstellen"; -static const char *kLabelCreateNew = "Neu..."; -static const char *kLabelDefaultInterface = "Standard"; -static const char *kLabelDeleteCurrent = "Auswahl Löschen"; -static const char *kLabelConnect = "Verbinden"; -static const char *kLabelDisconnect = "Trennen"; -static const char *kLabelOK = "OK"; -#else static const char *kLabelInterface = "Interface: "; static const char *kLabelInterfaceName = "Interface Name: "; static const char *kLabelCreateNewInterface = "Create New Interface"; @@ -65,23 +54,8 @@ static const char *kLabelDeleteCurrent = "Delete Current"; static const char *kLabelConnect = "Connect"; static const char *kLabelDisconnect = "Disconnect"; static const char *kLabelOK = "OK"; -#endif // connection status strings -#ifdef LANG_GERMAN -static const char *kTextConnecting = "Verbinde..."; -static const char *kTextConnectionEstablished = "Verbindung hergestellt."; -static const char *kTextNotConnected = "Nicht verbunden."; -static const char *kTextDeviceUpFailed = "Konnte Verbindung nicht aufbauen."; -static const char *kTextAuthenticating = "Authentifizierung..."; -static const char *kTextAuthenticationFailed = "Authentifizierung fehlgeschlagen!"; -static const char *kTextConnectionLost = "Verbindung verloren!"; -static const char *kTextCreationError = "Fehler beim Initialisieren!"; -static const char *kTextNoInterfacesFound = "Bitte erstellen Sie eine neue " - "Verbindung."; -static const char *kTextChooseInterfaceName = "Bitte denken Sie sich einen neuen " - "Namen für diese Verbindung aus."; -#else static const char *kTextConnecting = "Connecting..."; static const char *kTextConnectionEstablished = "Connection established."; static const char *kTextNotConnected = "Not connected."; @@ -93,19 +67,7 @@ static const char *kTextCreationError = "Error creating interface!"; static const char *kTextNoInterfacesFound = "Please create a new interface..."; static const char *kTextChooseInterfaceName = "Please choose a new name for this " "interface."; -#endif -// error strings for alerts -#ifdef LANG_GERMAN -static const char *kErrorTitle = "Fehler"; -static const char *kErrorNoPPPStack = "Fehler: Kein Zugriff auf den PPP Stack!"; -static const char *kErrorInterfaceExists = "Fehler: Eine Verbindung mit diesem Namen " - "existiert bereits!"; -static const char *kErrorLoadingFailed = "Fehler: Konfiguration ist fehlerhaft! Die " - "Einstellungen werden zurückgesetzt."; -static const char *kErrorSavingFailed = "Fehler: Speichern der Einstellungen ist " - "fehlgeschlagen!"; -#else static const char *kErrorTitle = "Error"; static const char *kErrorNoPPPStack = "Error: Could not access the PPP stack!"; static const char *kErrorInterfaceExists = "Error: An interface with this name " @@ -113,7 +75,6 @@ static const char *kErrorInterfaceExists = "Error: An interface with this name " static const char *kErrorLoadingFailed = "Error: Failed loading interface! The " "current settings will be deleted."; static const char *kErrorSavingFailed = "Error: Failed saving interface settings!"; -#endif static @@ -201,6 +162,7 @@ DialUpView::DialUpView(BRect frame) AddChild(fConnectButton); // initialize + fListener.WatchManager(); LoadInterfaces(); fSettings.LoadAddons(); CreateTabs(); @@ -267,9 +229,9 @@ DialUpView::MessageReceived(BMessage *message) UpdateControls(); // a newly created interface is set to default if there is no default one - if(!fSettings.DefaultInterface()) { + if(PPPManager::DefaultInterface() == "") { fDefaultInterface->SetValue(true); - fSettings.SetDefaultInterface(name); + PPPManager::SetDefaultInterface(name); } } break; // ------------------------------------------------- @@ -279,17 +241,14 @@ DialUpView::MessageReceived(BMessage *message) return; const char *name = fCurrentItem->Message()->FindString("name"); - if(fSettings.DefaultInterface() && !strcmp(fSettings.DefaultInterface(), - name)) - fSettings.SetDefaultInterface(NULL); + if(PPPManager::DefaultInterface() == name) + PPPManager::SetDefaultInterface(""); fInterfaceMenu->RemoveItem(fCurrentItem); - BDirectory settings, profile; - fSettings.GetPTPDirectories(&settings, &profile); + BDirectory settings; + PPPManager::GetSettingsDirectory(&settings); BEntry entry; settings.FindEntry(name, &entry); entry.Remove(); - profile.FindEntry(name, &entry); - entry.Remove(); delete fCurrentItem; fCurrentItem = NULL; @@ -331,25 +290,22 @@ void DialUpView::UpDownThread() { fSettings.SaveSettingsToFile(); - BMessage settings, profile; - fSettings.SaveSettings(&settings, &profile, true); - // save temporary profile - driver_settings *temporaryProfile = MessageToDriverSettings(profile); + BMessage settings; + fSettings.SaveSettings(&settings); PPPInterface interface; ppp_interface_info_t info; - // if going up: delete interface in order for the settings change to take effect + // if going up: delete interface in order for the settings changes to take effect interface = fListener.Manager().InterfaceWithName( fCurrentItem->Message()->FindString("name")); interface.GetInterfaceInfo(&info); - if(interface.InitCheck() == B_OK && info.info.phase == PPP_DOWN_PHASE) + if(interface.InitCheck() == B_OK && info.info.state == PPP_INITIAL_STATE + && info.info.phase == PPP_DOWN_PHASE) fListener.Manager().DeleteInterface(interface.ID()); interface = fListener.Manager().CreateInterfaceWithName( fCurrentItem->Message()->FindString("name")); - interface.SetProfile(temporaryProfile); - free_driver_settings(temporaryProfile); if(interface.InitCheck() != B_OK) { Window()->Lock(); @@ -359,9 +315,11 @@ DialUpView::UpDownThread() } interface.GetInterfaceInfo(&info); - if(info.info.phase == PPP_DOWN_PHASE) + if(info.info.state == PPP_INITIAL_STATE && info.info.phase == PPP_DOWN_PHASE) { + interface.SetPassword(fSettings.SessionPassword()); + interface.SetAskBeforeConnecting(false); interface.Up(); - else + } else interface.Down(); fUpDownThread = -1; @@ -371,11 +329,6 @@ DialUpView::UpDownThread() void DialUpView::HandleReportMessage(BMessage *message) { - thread_id sender; - message->FindInt32("sender", &sender); - - send_data(sender, B_OK, NULL, 0); - if(!fCurrentItem) return; @@ -457,14 +410,12 @@ void DialUpView::UpdateStatus(int32 code) { switch(code) { - case PPP_REPORT_UP_ABORTED: case PPP_REPORT_DEVICE_UP_FAILED: - case PPP_REPORT_LOCAL_AUTHENTICATION_FAILED: - case PPP_REPORT_PEER_AUTHENTICATION_FAILED: + case PPP_REPORT_AUTHENTICATION_FAILED: case PPP_REPORT_DOWN_SUCCESSFUL: - case PPP_REPORT_CONNECTION_LOST: { + case PPP_REPORT_CONNECTION_LOST: fConnectButton->SetLabel(kLabelConnect); - } break; + break; default: fConnectButton->SetLabel(kLabelDisconnect); @@ -492,7 +443,6 @@ DialUpView::UpdateStatus(int32 code) fStatusView->SetText(kTextConnectionEstablished); break; - case PPP_REPORT_UP_ABORTED: case PPP_REPORT_DOWN_SUCCESSFUL: fStatusView->SetText(kTextNotConnected); break; @@ -502,13 +452,11 @@ DialUpView::UpdateStatus(int32 code) fStatusView->SetText(kTextDeviceUpFailed); break; - case PPP_REPORT_LOCAL_AUTHENTICATION_REQUESTED: - case PPP_REPORT_PEER_AUTHENTICATION_REQUESTED: + case PPP_REPORT_AUTHENTICATION_REQUESTED: fStatusView->SetText(kTextAuthenticating); break; - case PPP_REPORT_LOCAL_AUTHENTICATION_FAILED: - case PPP_REPORT_PEER_AUTHENTICATION_FAILED: + case PPP_REPORT_AUTHENTICATION_FAILED: fKeepLabel = true; fStatusView->SetText(kTextAuthenticationFailed); break; @@ -546,7 +494,10 @@ DialUpView::WatchInterface(ppp_interface_id ID) // transform phase into status switch(info.info.phase) { case PPP_DOWN_PHASE: - UpdateStatus(PPP_REPORT_DOWN_SUCCESSFUL); + if(info.info.state == PPP_STARTING_STATE) + UpdateStatus(PPP_REPORT_GOING_UP); + else + UpdateStatus(PPP_REPORT_DOWN_SUCCESSFUL); break; case PPP_TERMINATION_PHASE: @@ -575,7 +526,7 @@ DialUpView::LoadInterfaces() BDirectory settingsDirectory; BEntry entry; BPath path; - fSettings.GetPTPDirectories(&settingsDirectory, NULL); + PPPManager::GetSettingsDirectory(&settingsDirectory); while(settingsDirectory.GetNextEntry(&entry) == B_OK) { if(entry.IsFile()) { entry.GetPath(&path); @@ -597,7 +548,7 @@ DialUpView::AddInterface(const char *name, bool isNew = false) BMessage *message = new BMessage(kMsgSelectInterface); message->AddString("name", name); BString label(name); - if(fSettings.DefaultInterface() && label == fSettings.DefaultInterface()) + if(PPPManager::DefaultInterface() == label) label << " (" << kLabelDefaultInterface << ")"; BMenuItem *item = new BMenuItem(label.String(), message); item->SetTarget(this); @@ -639,8 +590,7 @@ DialUpView::SelectInterface(int32 index, bool isNew = false) const char *name = fCurrentItem->Message() ? fCurrentItem->Message()->FindString("name") : NULL; - fDefaultInterface->SetValue(fSettings.DefaultInterface() && name - && !strcmp(fSettings.DefaultInterface(), name)); + fDefaultInterface->SetValue(name && PPPManager::DefaultInterface() == name); fCurrentItem->SetMarked(true); fDeleterItem->SetEnabled(true); fInterfaceMenu->Superitem()->SetLabel(name); @@ -672,16 +622,13 @@ DialUpView::CountInterfaces() const BMenuItem* -DialUpView::FindInterface(const char *name) +DialUpView::FindInterface(BString name) { - if(!name) - return NULL; - BMenuItem *item; for(int32 index = 0; index < CountInterfaces(); index++) { item = fInterfaceMenu->ItemAt(index); if(item && item->Message() && item->Message()->HasString("name") - && !strcmp(item->Message()->FindString("name"), name)) + && name == item->Message()->FindString("name")) return item; } @@ -724,9 +671,9 @@ void DialUpView::UpdateDefaultInterface() { const char *name = fCurrentItem->Message()->FindString("name"); - BMenuItem *defaultItem = FindInterface(fSettings.DefaultInterface()); + BMenuItem *defaultItem = FindInterface(PPPManager::DefaultInterface()); if(fDefaultInterface->Value()) { - if(!fSettings.SetDefaultInterface(name)) { + if(!PPPManager::SetDefaultInterface(name)) { fDefaultInterface->SetValue(0); return; } @@ -737,7 +684,7 @@ DialUpView::UpdateDefaultInterface() label << " (" << kLabelDefaultInterface << ")"; fCurrentItem->SetLabel(label.String()); } else { - fSettings.SetDefaultInterface(NULL); + PPPManager::SetDefaultInterface(""); fCurrentItem->SetLabel(name); } } diff --git a/src/tests/kits/net/DialUpPreflet/DialUpView.h b/src/tests/kits/net/DialUpPreflet/DialUpView.h index a27568118d..445b332011 100644 --- a/src/tests/kits/net/DialUpPreflet/DialUpView.h +++ b/src/tests/kits/net/DialUpPreflet/DialUpView.h @@ -1,5 +1,5 @@ /* - * Copyright 2003-2004, Waldemar Kornewald + * Copyright 2003-2005, Waldemar Kornewald * Distributed under the terms of the MIT License. */ @@ -24,9 +24,6 @@ class DialUpView : public BView { void UpDownThread(); private: - void GetPPPDirectories(BDirectory *settingsDirectory, - BDirectory *profileDirectory) const; - void HandleReportMessage(BMessage *message); void CreateTabs(); @@ -38,7 +35,7 @@ class DialUpView : public BView { void AddInterface(const char *name, bool isNew = false); void SelectInterface(int32 index, bool isNew = false); int32 CountInterfaces() const; - BMenuItem *FindInterface(const char *name); + BMenuItem *FindInterface(BString name); void UpdateControls(); void UpdateDefaultInterface(); diff --git a/src/tests/kits/net/DialUpPreflet/GeneralAddon.cpp b/src/tests/kits/net/DialUpPreflet/GeneralAddon.cpp index bfd9d7970d..428fe2898d 100644 --- a/src/tests/kits/net/DialUpPreflet/GeneralAddon.cpp +++ b/src/tests/kits/net/DialUpPreflet/GeneralAddon.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2003-2005, Waldemar Kornewald + * Copyright 2003-2005, Waldemar Kornewald * Distributed under the terms of the MIT License. */ @@ -30,17 +30,6 @@ static const uint32 kMsgSelectDevice = 'SELD'; static const uint32 kMsgSelectAuthenticator = 'SELA'; // labels -#ifdef LANG_GERMAN -static const char *kLabelGeneral = "Allgemein"; -static const char *kLabelDevice = "Gerät: "; -static const char *kLabelNoDevicesFound = "Keine Geräte Gefunden!"; -static const char *kLabelAuthenticator = "Login: "; -static const char *kLabelNoAuthenticatorsFound = "Keine Login-Methoden gefunden!"; -static const char *kLabelName = "Benutzername: "; -static const char *kLabelPassword = "Password: "; -static const char *kLabelSavePassword = "Passwort Speichern"; -static const char *kLabelNone = "Ohne"; -#else static const char *kLabelGeneral = "General"; static const char *kLabelDevice = "Device: "; static const char *kLabelNoDevicesFound = "No Devices Found!"; @@ -50,7 +39,6 @@ static const char *kLabelName = "Username: "; static const char *kLabelPassword = "Password: "; static const char *kLabelSavePassword = "Save Password"; static const char *kLabelNone = "None"; -#endif // string constants for information saved in the settings message static const char *kGeneralTabAuthentication = "Authentication"; @@ -67,7 +55,6 @@ GeneralAddon::GeneralAddon(BMessage *addons) fDeleteView(false), fAuthenticatorsCount(0), fSettings(NULL), - fProfile(NULL), fGeneralView(NULL) { } @@ -80,6 +67,15 @@ GeneralAddon::~GeneralAddon() } +const char* +GeneralAddon::SessionPassword() const +{ + if(fGeneralView && fGeneralView->AuthenticatorName()) + return fGeneralView->Password(); + return NULL; +} + + DialUpAddon* GeneralAddon::FindDevice(const BString& moduleName) const { @@ -94,7 +90,7 @@ GeneralAddon::FindDevice(const BString& moduleName) const bool -GeneralAddon::LoadSettings(BMessage *settings, BMessage *profile, bool isNew) +GeneralAddon::LoadSettings(BMessage *settings, bool isNew) { fIsNew = isNew; fHasPassword = false; @@ -102,7 +98,6 @@ GeneralAddon::LoadSettings(BMessage *settings, BMessage *profile, bool isNew) fDeviceAddon = NULL; fAuthenticatorsCount = 0; fSettings = settings; - fProfile = profile; if(!fGeneralView) { CreateView(BPoint(0,0)); @@ -112,7 +107,7 @@ GeneralAddon::LoadSettings(BMessage *settings, BMessage *profile, bool isNew) fGeneralView->Reload(); // reset all views (empty settings) - if(!settings || !profile || isNew) + if(!settings || isNew) return true; if(!LoadDeviceSettings()) @@ -148,18 +143,17 @@ GeneralAddon::LoadDeviceSettings() if(!fDeviceAddon) return false; - return fDeviceAddon->LoadSettings(fSettings, fProfile, false); + return fDeviceAddon->LoadSettings(fSettings, false); } bool GeneralAddon::LoadAuthenticationSettings() { - // we only handle the profile (although settings could contain different data) int32 itemIndex = 0; BMessage authentication, item; - if(!FindMessageParameter(PPP_AUTHENTICATOR_KEY, *fProfile, &item, &itemIndex)) + if(!FindMessageParameter(PPP_AUTHENTICATOR_KEY, *fSettings, &item, &itemIndex)) return true; // find authenticators (though we load all authenticators, we only use one) @@ -183,73 +177,66 @@ GeneralAddon::LoadAuthenticationSettings() // load username and password BMessage parameter; int32 parameterIndex = 0; - if(FindMessageParameter("User", item, ¶meter, ¶meterIndex) + if(FindMessageParameter("Username", *fSettings, ¶meter, ¶meterIndex) && parameter.FindString(MDSU_VALUES, &fUsername) == B_OK) { hasUsername = true; parameter.AddBool(MDSU_VALID, true); - item.ReplaceMessage(MDSU_PARAMETERS, parameterIndex, ¶meter); + fSettings->ReplaceMessage(MDSU_PARAMETERS, parameterIndex, ¶meter); } parameterIndex = 0; - if(FindMessageParameter("Password", item, ¶meter, ¶meterIndex) + if(FindMessageParameter("Password", *fSettings, ¶meter, ¶meterIndex) && parameter.FindString(MDSU_VALUES, &fPassword) == B_OK) { fHasPassword = true; parameter.AddBool(MDSU_VALID, true); - item.ReplaceMessage(MDSU_PARAMETERS, parameterIndex, ¶meter); + fSettings->ReplaceMessage(MDSU_PARAMETERS, parameterIndex, ¶meter); } // tell DUN whether everything is valid if(hasUsername) item.AddBool(MDSU_VALID, true); - fProfile->ReplaceMessage(MDSU_PARAMETERS, itemIndex, &item); + fSettings->ReplaceMessage(MDSU_PARAMETERS, itemIndex, &item); return true; } -bool -GeneralAddon::HasTemporaryProfile() const -{ - return fGeneralView->HasTemporaryProfile(); -} - - void -GeneralAddon::IsModified(bool *settings, bool *profile) const +GeneralAddon::IsModified(bool *settings) const { if(!fSettings) { - *settings = *profile = false; + *settings = false; return; } - bool deviceSettings, authenticationSettings, deviceProfile, authenticationProfile; + bool deviceSettings, authenticationSettings; - IsDeviceModified(&deviceSettings, &deviceProfile); - IsAuthenticationModified(&authenticationSettings, &authenticationProfile); + IsDeviceModified(&deviceSettings); + IsAuthenticationModified(&authenticationSettings); *settings = (deviceSettings || authenticationSettings); - *profile = (deviceProfile || authenticationProfile); } void -GeneralAddon::IsDeviceModified(bool *settings, bool *profile) const +GeneralAddon::IsDeviceModified(bool *settings) const { - fGeneralView->IsDeviceModified(settings, profile); + fGeneralView->IsDeviceModified(settings); } void -GeneralAddon::IsAuthenticationModified(bool *settings, bool *profile) const +GeneralAddon::IsAuthenticationModified(bool *settings) const { // currently we only support selecting one authenticator if(fAuthenticatorsCount == 0) *settings = fGeneralView->AuthenticatorName(); else { BMessage authentication; - if(fSettings->FindMessage(kGeneralTabAuthentication, &authentication) != B_OK) { - *settings = *profile = false; + if(fSettings->FindMessage(kGeneralTabAuthentication, + &authentication) != B_OK) { + *settings = false; return; // error! } @@ -257,30 +244,29 @@ GeneralAddon::IsAuthenticationModified(bool *settings, bool *profile) const BString authenticator; if(authentication.FindString(kGeneralTabAuthenticators, &authenticator) != B_OK) { - *settings = *profile = false; + *settings = false; return; // error! } *settings = (!fGeneralView->AuthenticatorName() - || authenticator != fGeneralView->AuthenticatorName()); + || authenticator != fGeneralView->AuthenticatorName() + || fUsername != fGeneralView->Username() + || (fPassword != fGeneralView->Password() && fHasPassword) + || fHasPassword != fGeneralView->DoesSavePassword()); } - - *profile = (*settings || fUsername != fGeneralView->Username() - || (fPassword != fGeneralView->Password() && fHasPassword) - || fHasPassword != fGeneralView->DoesSavePassword()); } bool -GeneralAddon::SaveSettings(BMessage *settings, BMessage *profile, bool saveTemporary) +GeneralAddon::SaveSettings(BMessage *settings) { if(!fSettings || !settings || !fGeneralView->DeviceName()) return false; // TODO: tell user that a device is needed (if we fail because of this) - if(!fGeneralView->DeviceAddon() || !fGeneralView->DeviceAddon()->SaveSettings( - settings, profile, saveTemporary)) + if(!fGeneralView->DeviceAddon() + || !fGeneralView->DeviceAddon()->SaveSettings(settings)) return false; if(fGeneralView->AuthenticatorName()) { @@ -290,19 +276,17 @@ GeneralAddon::SaveSettings(BMessage *settings, BMessage *profile, bool saveTempo settings->AddMessage(MDSU_PARAMETERS, &authenticator); BMessage username; - username.AddString(MDSU_NAME, "User"); + username.AddString(MDSU_NAME, PPP_USERNAME_KEY); username.AddString(MDSU_VALUES, fGeneralView->Username()); - authenticator.AddMessage(MDSU_PARAMETERS, &username); + settings->AddMessage(MDSU_PARAMETERS, &username); - if(saveTemporary || fGeneralView->DoesSavePassword()) { + if(fGeneralView->DoesSavePassword()) { // save password, too BMessage password; - password.AddString(MDSU_NAME, "Password"); + password.AddString(MDSU_NAME, PPP_PASSWORD_KEY); password.AddString(MDSU_VALUES, fGeneralView->Password()); - authenticator.AddMessage(MDSU_PARAMETERS, &password); + settings->AddMessage(MDSU_PARAMETERS, &password); } - - profile->AddMessage(MDSU_PARAMETERS, &authenticator); } return true; @@ -466,7 +450,7 @@ GeneralView::Reload() item = fDeviceField->Menu()->ItemAt(0); item->SetMarked(true); item->Message()->FindPointer("Addon", reinterpret_cast(&fDeviceAddon)); - fDeviceAddon->LoadSettings(Addon()->Settings(), Addon()->Profile(), true); + fDeviceAddon->LoadSettings(Addon()->Settings(), true); } else { fDeviceAddon = NULL; item = fDeviceField->Menu()->FindMarked(); @@ -526,14 +510,14 @@ GeneralView::AuthenticatorName() const void -GeneralView::IsDeviceModified(bool *settings, bool *profile) const +GeneralView::IsDeviceModified(bool *settings) const { if(fDeviceAddon != Addon()->DeviceAddon()) - *settings = *profile = true; + *settings = true; else if(fDeviceAddon) - fDeviceAddon->IsModified(settings, profile); + fDeviceAddon->IsModified(settings); else - *settings = *profile = false; + *settings = false; } @@ -558,8 +542,7 @@ GeneralView::MessageReceived(BMessage *message) fDeviceAddon = NULL; else { if(fDeviceAddon != Addon()->DeviceAddon()) - fDeviceAddon->LoadSettings(Addon()->Settings(), Addon()->Profile(), - Addon()->IsNew()); + fDeviceAddon->LoadSettings(Addon()->Settings(), Addon()->IsNew()); ReloadDeviceView(); } diff --git a/src/tests/kits/net/DialUpPreflet/GeneralAddon.h b/src/tests/kits/net/DialUpPreflet/GeneralAddon.h index bb6160f4b9..2ab48613d6 100644 --- a/src/tests/kits/net/DialUpPreflet/GeneralAddon.h +++ b/src/tests/kits/net/DialUpPreflet/GeneralAddon.h @@ -1,5 +1,5 @@ /* - * Copyright 2003-2004, Waldemar Kornewald + * Copyright 2003-2005, Waldemar Kornewald * Distributed under the terms of the MIT License. */ @@ -34,6 +34,7 @@ class GeneralAddon : public DialUpAddon { { return fUsername.String(); } const char *Password() const { return fPassword.String(); } + const char *SessionPassword() const; bool HasPassword() const { return fHasPassword; } @@ -46,22 +47,18 @@ class GeneralAddon : public DialUpAddon { BMessage *Settings() const { return fSettings; } - BMessage *Profile() const - { return fProfile; } virtual int32 Position() const { return 0; } - virtual bool LoadSettings(BMessage *settings, BMessage *profile, bool isNew); + virtual bool LoadSettings(BMessage *settings, bool isNew); bool LoadDeviceSettings(); bool LoadAuthenticationSettings(); - virtual bool HasTemporaryProfile() const; - virtual void IsModified(bool *settings, bool *profile) const; - void IsDeviceModified(bool *settings, bool *profile) const; - void IsAuthenticationModified(bool *settings, bool *profile) const; + virtual void IsModified(bool *settings) const; + void IsDeviceModified(bool *settings) const; + void IsAuthenticationModified(bool *settings) const; - virtual bool SaveSettings(BMessage *settings, BMessage *profile, - bool saveTemporary); + virtual bool SaveSettings(BMessage *settings); virtual bool GetPreferredSize(float *width, float *height) const; virtual BView *CreateView(BPoint leftTop); @@ -74,7 +71,7 @@ class GeneralAddon : public DialUpAddon { BString fDeviceName, fUsername, fPassword; DialUpAddon *fDeviceAddon; int32 fAuthenticatorsCount; - BMessage *fSettings, *fProfile; + BMessage *fSettings; // saves last settings state GeneralView *fGeneralView; }; @@ -96,15 +93,11 @@ class GeneralView : public BView { bool DoesSavePassword() const { return fSavePassword->Value(); } - bool HasTemporaryProfile() const - { return !DoesSavePassword() || (fDeviceAddon && - fDeviceAddon->HasTemporaryProfile()); } - DialUpAddon *DeviceAddon() const { return fDeviceAddon; } const char *DeviceName() const; const char *AuthenticatorName() const; - void IsDeviceModified(bool *settings, bool *profile) const; + void IsDeviceModified(bool *settings) const; virtual void AttachedToWindow(); virtual void MessageReceived(BMessage *message); diff --git a/src/tests/kits/net/DialUpPreflet/IPCPAddon.cpp b/src/tests/kits/net/DialUpPreflet/IPCPAddon.cpp index e88954ceb1..9a62bbcd1f 100644 --- a/src/tests/kits/net/DialUpPreflet/IPCPAddon.cpp +++ b/src/tests/kits/net/DialUpPreflet/IPCPAddon.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2003-2004, Waldemar Kornewald + * Copyright 2003-2005, Waldemar Kornewald * Distributed under the terms of the MIT License. */ @@ -28,15 +28,6 @@ static const uint32 kDefaultButtonWidth = 80; static const uint32 kMsgUpdateControls = 'UCTL'; // labels -#ifdef LANG_GERMAN -static const char *kLabelIPCP = "TCP/IP"; -static const char *kLabelIPAddress = "IP Adresse: "; -static const char *kLabelPrimaryDNS = "Primärer DNS: "; -static const char *kLabelSecondaryDNS = "Sekundärer DNS: "; -static const char *kLabelOptional = "(Optional)"; -static const char *kLabelExtendedOptions = "Erweiterte Optionen:"; -static const char *kLabelEnabled = "TCP/IP-Protokoll Verwenden"; -#else static const char *kLabelIPCP = "TCP/IP"; static const char *kLabelIPAddress = "IP Address: "; static const char *kLabelPrimaryDNS = "Primary DNS: "; @@ -44,7 +35,6 @@ static const char *kLabelSecondaryDNS = "Secondary DNS: "; static const char *kLabelOptional = "(Optional)"; static const char *kLabelExtendedOptions = "Extended Options:"; static const char *kLabelEnabled = "Enable TCP/IP Protocol"; -#endif // add-on descriptions static const char *kKernelModuleName = "ipcp"; @@ -53,7 +43,6 @@ static const char *kKernelModuleName = "ipcp"; IPCPAddon::IPCPAddon(BMessage *addons) : DialUpAddon(addons), fSettings(NULL), - fProfile(NULL), fIPCPView(NULL) { CreateView(BPoint(0,0)); @@ -69,23 +58,21 @@ IPCPAddon::~IPCPAddon() bool -IPCPAddon::LoadSettings(BMessage *settings, BMessage *profile, bool isNew) +IPCPAddon::LoadSettings(BMessage *settings, bool isNew) { fIsNew = isNew; fIsEnabled = false; fIPAddress = fPrimaryDNS = fSecondaryDNS = ""; fSettings = settings; - fProfile = profile; fIPCPView->Reload(); // reset all views (empty settings) - if(!settings || !profile || isNew) + if(!settings || isNew) return true; BMessage protocol; - // settings int32 protocolIndex = FindIPCPProtocol(*fSettings, &protocol); if(protocolIndex < 0) return true; @@ -93,11 +80,6 @@ IPCPAddon::LoadSettings(BMessage *settings, BMessage *profile, bool isNew) protocol.AddBool(MDSU_VALID, true); fSettings->ReplaceMessage(MDSU_PARAMETERS, protocolIndex, &protocol); - // profile - protocolIndex = FindIPCPProtocol(*fProfile, &protocol); - if(protocolIndex < 0) - return true; - fIsEnabled = true; // the "Local" side parameter @@ -149,7 +131,7 @@ IPCPAddon::LoadSettings(BMessage *settings, BMessage *profile, bool isNew) local.AddBool(MDSU_VALID, true); protocol.ReplaceMessage(MDSU_PARAMETERS, localSideIndex, &local); protocol.AddBool(MDSU_VALID, true); - fProfile->ReplaceMessage(MDSU_PARAMETERS, protocolIndex, &protocol); + fSettings->ReplaceMessage(MDSU_PARAMETERS, protocolIndex, &protocol); fIPCPView->Reload(); @@ -158,22 +140,22 @@ IPCPAddon::LoadSettings(BMessage *settings, BMessage *profile, bool isNew) void -IPCPAddon::IsModified(bool *settings, bool *profile) const +IPCPAddon::IsModified(bool *settings) const { if(!fSettings) { - *settings = *profile = false; + *settings = false; return; } - *settings = fIsEnabled != fIPCPView->IsEnabled(); - *profile = (*settings || fIPAddress != fIPCPView->IPAddress() + *settings = (fIsEnabled != fIPCPView->IsEnabled() + || fIPAddress != fIPCPView->IPAddress() || fPrimaryDNS != fIPCPView->PrimaryDNS() || fSecondaryDNS != fIPCPView->SecondaryDNS()); } bool -IPCPAddon::SaveSettings(BMessage *settings, BMessage *profile, bool saveTemporary) +IPCPAddon::SaveSettings(BMessage *settings) { if(!fSettings || !settings) return false; @@ -184,10 +166,9 @@ IPCPAddon::SaveSettings(BMessage *settings, BMessage *profile, bool saveTemporar BMessage protocol, local; protocol.AddString(MDSU_NAME, PPP_PROTOCOL_KEY); protocol.AddString(MDSU_VALUES, kKernelModuleName); - settings->AddMessage(MDSU_PARAMETERS, &protocol); // the settings contain a simple "protocol ipcp" string - // now create the profile with all subparameters + // now create the settings with all subparameters local.AddString(MDSU_NAME, IPCP_LOCAL_SIDE_KEY); bool needsLocal = false; @@ -221,7 +202,7 @@ IPCPAddon::SaveSettings(BMessage *settings, BMessage *profile, bool saveTemporar if(needsLocal) protocol.AddMessage(MDSU_PARAMETERS, &local); - profile->AddMessage(MDSU_PARAMETERS, &protocol); + settings->AddMessage(MDSU_PARAMETERS, &protocol); return true; } diff --git a/src/tests/kits/net/DialUpPreflet/IPCPAddon.h b/src/tests/kits/net/DialUpPreflet/IPCPAddon.h index 40d36c92a7..5157435eb2 100644 --- a/src/tests/kits/net/DialUpPreflet/IPCPAddon.h +++ b/src/tests/kits/net/DialUpPreflet/IPCPAddon.h @@ -1,5 +1,5 @@ /* - * Copyright 2003-2004, Waldemar Kornewald + * Copyright 2003-2005, Waldemar Kornewald * Distributed under the terms of the MIT License. */ @@ -39,16 +39,13 @@ class IPCPAddon : public DialUpAddon { BMessage *Settings() const { return fSettings; } - BMessage *Profile() const - { return fProfile; } virtual int32 Position() const { return 10; } - virtual bool LoadSettings(BMessage *settings, BMessage *profile, bool isNew); - virtual void IsModified(bool *settings, bool *profile) const; - virtual bool SaveSettings(BMessage *settings, BMessage *profile, - bool saveTemporary); + virtual bool LoadSettings(BMessage *settings, bool isNew); + virtual void IsModified(bool *settings) const; + virtual bool SaveSettings(BMessage *settings); virtual bool GetPreferredSize(float *width, float *height) const; virtual BView *CreateView(BPoint leftTop); @@ -58,7 +55,7 @@ class IPCPAddon : public DialUpAddon { private: bool fIsNew, fIsEnabled, fDeleteView; BString fIPAddress, fPrimaryDNS, fSecondaryDNS; - BMessage *fSettings, *fProfile; + BMessage *fSettings; // saves last settings state IPCPView *fIPCPView; }; diff --git a/src/tests/kits/net/DialUpPreflet/InterfaceUtils.cpp b/src/tests/kits/net/DialUpPreflet/InterfaceUtils.cpp index 59d57f89b1..2698699b3f 100644 --- a/src/tests/kits/net/DialUpPreflet/InterfaceUtils.cpp +++ b/src/tests/kits/net/DialUpPreflet/InterfaceUtils.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2004, Waldemar Kornewald + * Copyright 2004, Waldemar Kornewald * Distributed under the terms of the MIT License. */ diff --git a/src/tests/kits/net/DialUpPreflet/InterfaceUtils.h b/src/tests/kits/net/DialUpPreflet/InterfaceUtils.h index e3419e8612..a1559893bd 100644 --- a/src/tests/kits/net/DialUpPreflet/InterfaceUtils.h +++ b/src/tests/kits/net/DialUpPreflet/InterfaceUtils.h @@ -1,5 +1,5 @@ /* - * Copyright 2004, Waldemar Kornewald + * Copyright 2004, Waldemar Kornewald * Distributed under the terms of the MIT License. */ diff --git a/src/tests/kits/net/DialUpPreflet/Jamfile b/src/tests/kits/net/DialUpPreflet/Jamfile index e060992e4c..f6642f5d77 100644 --- a/src/tests/kits/net/DialUpPreflet/Jamfile +++ b/src/tests/kits/net/DialUpPreflet/Jamfile @@ -1,18 +1,5 @@ SubDir OBOS_TOP src tests kits net DialUpPreflet ; -# set some additional defines -{ - local defines ; - - if $(LANG_GERMAN) { - defines += LANG_GERMAN ; - } - - defines = [ FDefines $(defines) ] ; - SubDirCcFlags $(defines) ; - SubDirC++Flags $(defines) ; -} - UsePrivateHeaders net ; UseHeaders [ FDirName $(OBOS_TOP) src add-ons kernel network ppp shared libppp headers ] ; UseHeaders [ FDirName $(OBOS_TOP) src add-ons kernel network ppp shared libkernelppp headers ] ; @@ -23,13 +10,15 @@ UseHeaders [ FDirName $(OBOS_TOP) src add-ons kernel network ppp ipcp ] ; # IPCP AddResources DialUpPreflet : DialUpPreflet.rdef ; -StaticLibrary ptpnet : - PTPSettings.cpp +SimpleTest DialUpPreflet : + # Application + DialUpApplication.cpp + DialUpView.cpp - # utils (TODO: move into their own library) + # utils (TODO: move some of them into a separate library) InterfaceUtils.cpp - MessageDriverSettingsUtils.cpp TextRequestDialog.cpp + PTPSettings.cpp # built-in add-ons ConnectionOptionsAddon.cpp @@ -38,9 +27,4 @@ StaticLibrary ptpnet : PPPoEAddon.cpp ; -SimpleTest DialUpPreflet : - DialUpApplication.cpp - DialUpView.cpp -; - -LinkSharedOSLibs DialUpPreflet : libptpnet.a libppp.a be ; +LinkSharedOSLibs DialUpPreflet : libppp.a be ; diff --git a/src/tests/kits/net/DialUpPreflet/PPPoEAddon.cpp b/src/tests/kits/net/DialUpPreflet/PPPoEAddon.cpp index c87e46c38a..a9bb1292f3 100644 --- a/src/tests/kits/net/DialUpPreflet/PPPoEAddon.cpp +++ b/src/tests/kits/net/DialUpPreflet/PPPoEAddon.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2003-2004, Waldemar Kornewald + * Copyright 2003-2005, Waldemar Kornewald * Distributed under the terms of the MIT License. */ @@ -39,33 +39,17 @@ static const uint32 kMsgChangeService = 'CHGS'; static const uint32 kMsgResetService = 'RESS'; // labels -#ifdef LANG_GERMAN -static const char *kLabelInterfaceName = "Netzwerk-Adapter: "; -static const char *kLabelOptional = "(Optional)"; -static const char *kLabelOtherInterface = "Anderer:"; -static const char *kLabelSelectInterface = "Adapter Auswählen..."; -static const char *kLabelServiceName = "Service: "; -#else static const char *kLabelInterfaceName = "Network Interface: "; static const char *kLabelOptional = "(Optional)"; static const char *kLabelOtherInterface = "Other:"; static const char *kLabelSelectInterface = "Select Interface..."; static const char *kLabelServiceName = "Service: "; -#endif // requests -#ifdef LANG_GERMAN -static const char *kRequestInterfaceName = "Name Des Adapters: "; -#else static const char *kRequestInterfaceName = "Network Interface Name: "; -#endif // add-on descriptions -#ifdef LANG_GERMAN -static const char *kFriendlyName = "Breitband: DSL, Kabel, etc."; -#else static const char *kFriendlyName = "Broadband: DSL, Cable, etc."; -#endif static const char *kTechnicalName = "PPPoE"; static const char *kKernelModuleName = "pppoe"; @@ -73,7 +57,6 @@ static const char *kKernelModuleName = "pppoe"; PPPoEAddon::PPPoEAddon(BMessage *addons) : DialUpAddon(addons), fSettings(NULL), - fProfile(NULL), fPPPoEView(NULL) { fHeight = 20 // interface name control @@ -111,16 +94,15 @@ PPPoEAddon::KernelModuleName() const bool -PPPoEAddon::LoadSettings(BMessage *settings, BMessage *profile, bool isNew) +PPPoEAddon::LoadSettings(BMessage *settings, bool isNew) { fIsNew = isNew; fInterfaceName = fServiceName = ""; fSettings = settings; - fProfile = profile; fPPPoEView->Reload(); - if(!settings || !profile || isNew) + if(!settings || isNew) return true; BMessage device; @@ -164,10 +146,8 @@ PPPoEAddon::LoadSettings(BMessage *settings, BMessage *profile, bool isNew) void -PPPoEAddon::IsModified(bool *settings, bool *profile) const +PPPoEAddon::IsModified(bool *settings) const { - *profile = false; - if(!fSettings) { *settings = false; return; @@ -179,7 +159,7 @@ PPPoEAddon::IsModified(bool *settings, bool *profile) const bool -PPPoEAddon::SaveSettings(BMessage *settings, BMessage *profile, bool saveTemporary) +PPPoEAddon::SaveSettings(BMessage *settings) { if(!fSettings || !settings || !fPPPoEView->InterfaceName() || strlen(fPPPoEView->InterfaceName()) == 0) diff --git a/src/tests/kits/net/DialUpPreflet/PPPoEAddon.h b/src/tests/kits/net/DialUpPreflet/PPPoEAddon.h index a8206be08f..acb16ba5da 100644 --- a/src/tests/kits/net/DialUpPreflet/PPPoEAddon.h +++ b/src/tests/kits/net/DialUpPreflet/PPPoEAddon.h @@ -1,5 +1,5 @@ /* - * Copyright 2003-2004, Waldemar Kornewald + * Copyright 2003-2005, Waldemar Kornewald * Distributed under the terms of the MIT License. */ @@ -34,19 +34,16 @@ class PPPoEAddon : public DialUpAddon { BMessage *Settings() const { return fSettings; } - BMessage *Profile() const - { return fProfile; } virtual const char *FriendlyName() const; virtual const char *TechnicalName() const; virtual const char *KernelModuleName() const; - virtual bool LoadSettings(BMessage *settings, BMessage *profile, bool isNew); + virtual bool LoadSettings(BMessage *settings, bool isNew); - virtual void IsModified(bool *settings, bool *profile) const; + virtual void IsModified(bool *settings) const; - virtual bool SaveSettings(BMessage *settings, BMessage *profile, - bool saveTemporary); + virtual bool SaveSettings(BMessage *settings); virtual bool GetPreferredSize(float *width, float *height) const; virtual BView *CreateView(BPoint leftTop); @@ -56,7 +53,7 @@ class PPPoEAddon : public DialUpAddon { private: bool fIsNew; BString fInterfaceName, fServiceName; - BMessage *fSettings, *fProfile; + BMessage *fSettings; // saves last settings state PPPoEView *fPPPoEView; float fHeight; diff --git a/src/tests/kits/net/DialUpPreflet/PTPSettings.cpp b/src/tests/kits/net/DialUpPreflet/PTPSettings.cpp index f442f0168d..309e60345e 100644 --- a/src/tests/kits/net/DialUpPreflet/PTPSettings.cpp +++ b/src/tests/kits/net/DialUpPreflet/PTPSettings.cpp @@ -1,12 +1,14 @@ /* - * Copyright 2004, Waldemar Kornewald + * Copyright 2005, Waldemar Kornewald * Distributed under the terms of the MIT License. */ #include -// built-in add-ons #include +#include + +// built-in add-ons #include "ConnectionOptionsAddon.h" #include "GeneralAddon.h" #include "IPCPAddon.h" @@ -22,17 +24,11 @@ PTPSettings::PTPSettings() { - void *handle = load_driver_settings("ptpnet.settings"); - const char *name = get_driver_parameter(handle, "default", NULL, NULL); - fDefaultInterface = name ? strdup(name) : NULL; - unload_driver_settings(handle); } PTPSettings::~PTPSettings() { - free(fDefaultInterface); - // free known add-on types (these should free their known add-on types, etc.) DialUpAddon *addon; for(int32 index = 0; @@ -43,68 +39,11 @@ PTPSettings::~PTPSettings() } -bool -PTPSettings::SetDefaultInterface(const char *name) -{ - // load current settings and replace value of "default" with - BMessage settings; - if(!ReadMessageDriverSettings("ptpnet.settings", &settings)) - settings.MakeEmpty(); - - BMessage parameter; - int32 index = 0; - if(FindMessageParameter("default", settings, ¶meter, &index)) - settings.RemoveData(MDSU_PARAMETERS, index); - - parameter.MakeEmpty(); - if(name) { - parameter.AddString(MDSU_NAME, "default"); - parameter.AddString(MDSU_VALUES, name); - settings.AddMessage(MDSU_PARAMETERS, ¶meter); - } - - BFile file(PTP_SETTINGS_PATH, B_WRITE_ONLY | B_CREATE_FILE | B_ERASE_FILE); - if(file.InitCheck() != B_OK) - return false; - - if(WriteMessageDriverSettings(file, settings)) { - free(fDefaultInterface); - fDefaultInterface = name ? strdup(name) : NULL; - return true; - } else - return false; -} - -bool -PTPSettings::GetPTPDirectories(BDirectory *settingsDirectory, - BDirectory *profileDirectory) const +const char* +PTPSettings::SessionPassword() const { - if(settingsDirectory) { - BDirectory settings(PTP_INTERFACE_SETTINGS_PATH); - if(settings.InitCheck() != B_OK) { - create_directory(PTP_INTERFACE_SETTINGS_PATH, 0750); - settings.SetTo(PTP_INTERFACE_SETTINGS_PATH); - if(settings.InitCheck() != B_OK) - return false; - } - - *settingsDirectory = settings; - } - - if(profileDirectory) { - BDirectory profile(PTP_INTERFACE_SETTINGS_PATH "/profile"); - if(profile.InitCheck() != B_OK) { - create_directory(PTP_INTERFACE_SETTINGS_PATH "/profile", 0750); - profile.SetTo(PTP_INTERFACE_SETTINGS_PATH "/profile"); - if(profile.InitCheck() != B_OK) - return false; - } - - *profileDirectory = profile; - } - - return true; + return fGeneralAddon->SessionPassword(); } @@ -116,19 +55,13 @@ PTPSettings::LoadSettings(const char *interfaceName, bool isNew) fCurrent = interfaceName ? interfaceName : ""; fSettings.MakeEmpty(); - fProfile.MakeEmpty(); - BMessage *settingsPointer = interfaceName ? &fSettings : NULL, - *profilePointer = interfaceName ? &fProfile : NULL; + BMessage *settingsPointer = interfaceName ? &fSettings : NULL; if(interfaceName && !isNew) { BString name("ptpnet/"); name << fCurrent; if(!ReadMessageDriverSettings(name.String(), &fSettings)) return false; - name = "ptpnet/profile/"; - name << fCurrent; - if(!ReadMessageDriverSettings(name.String(), &fProfile)) - profilePointer = settingsPointer; } DialUpAddon *addon; @@ -137,7 +70,7 @@ PTPSettings::LoadSettings(const char *interfaceName, bool isNew) if(!addon) continue; - if(!addon->LoadSettings(settingsPointer, profilePointer, isNew)) + if(!addon->LoadSettings(settingsPointer, isNew)) return false; } @@ -148,11 +81,10 @@ PTPSettings::LoadSettings(const char *interfaceName, bool isNew) void -PTPSettings::IsModified(bool *settings, bool *profile) +PTPSettings::IsModified(bool *settings) { - *settings = *profile = false; - bool addonSettingsChanged, addonProfileChanged; - // for current addon + *settings = false; + bool addonSettingsChanged; DialUpAddon *addon; for(int32 index = 0; fAddons.FindPointer(DUN_TAB_ADDON_TYPE, index, @@ -160,19 +92,17 @@ PTPSettings::IsModified(bool *settings, bool *profile) if(!addon) continue; - addon->IsModified(&addonSettingsChanged, &addonProfileChanged); + addon->IsModified(&addonSettingsChanged); if(addonSettingsChanged) *settings = true; - if(addonProfileChanged) - *profile = true; } } bool -PTPSettings::SaveSettings(BMessage *settings, BMessage *profile, bool saveTemporary) +PTPSettings::SaveSettings(BMessage *settings) { - if(fCurrent.Length() == 0 || !settings || !profile) + if(fCurrent.Length() == 0 || !settings) return false; DialUpAddon *addon; @@ -199,7 +129,7 @@ PTPSettings::SaveSettings(BMessage *settings, BMessage *profile, bool saveTempor settings->AddString("InterfaceName", fCurrent); for(int32 index = 0; index < addons.CountItems(); index++) - if(!addons.ItemAt(index)->SaveSettings(settings, profile, saveTemporary)) + if(!addons.ItemAt(index)->SaveSettings(settings)) return false; return true; @@ -209,18 +139,17 @@ PTPSettings::SaveSettings(BMessage *settings, BMessage *profile, bool saveTempor bool PTPSettings::SaveSettingsToFile() { - bool settingsChanged, profileChanged; - IsModified(&settingsChanged, &profileChanged); - if(!settingsChanged && !profileChanged) + bool settingsChanged; + IsModified(&settingsChanged); + if(!settingsChanged) return true; - BMessage settings, profile; - if(!SaveSettings(&settings, &profile, false)) + BMessage settings; + if(!SaveSettings(&settings)) return false; BDirectory settingsDirectory; - BDirectory profileDirectory; - if(!GetPTPDirectories(&settingsDirectory, &profileDirectory)) + if(!PPPManager::GetSettingsDirectory(&settingsDirectory)) return false; BFile file; @@ -229,17 +158,12 @@ PTPSettings::SaveSettingsToFile() WriteMessageDriverSettings(file, settings); } - if(profileChanged) { - profileDirectory.CreateFile(fCurrent.String(), &file); - WriteMessageDriverSettings(file, profile); - } - return true; } void -PTPSettings::LoadAddons(bool loadGeneralAddon = true) +PTPSettings::LoadAddons() { // Load built-in add-ons: // "Connection Options" tab @@ -248,11 +172,9 @@ PTPSettings::LoadAddons(bool loadGeneralAddon = true) fAddons.AddPointer(DUN_TAB_ADDON_TYPE, connectionOptionsAddon); fAddons.AddPointer(DUN_DELETE_ON_QUIT, connectionOptionsAddon); // "General" tab - if(loadGeneralAddon) { - GeneralAddon *fGeneralAddon = new GeneralAddon(&fAddons); - fAddons.AddPointer(DUN_TAB_ADDON_TYPE, fGeneralAddon); - fAddons.AddPointer(DUN_DELETE_ON_QUIT, fGeneralAddon); - } + fGeneralAddon = new GeneralAddon(&fAddons); + fAddons.AddPointer(DUN_TAB_ADDON_TYPE, fGeneralAddon); + fAddons.AddPointer(DUN_DELETE_ON_QUIT, fGeneralAddon); // "IPCP" protocol IPCPAddon *ipcpAddon = new IPCPAddon(&fAddons); fAddons.AddPointer(DUN_TAB_ADDON_TYPE, ipcpAddon); @@ -264,11 +186,7 @@ PTPSettings::LoadAddons(bool loadGeneralAddon = true) // "PAP" authenticator BMessage addon; -#ifdef LANG_GERMAN - addon.AddString("FriendlyName", "Unverschlüsselt"); -#else addon.AddString("FriendlyName", "Plain-text Authentication"); -#endif addon.AddString("TechnicalName", "PAP"); addon.AddString("KernelModuleName", "pap"); fAddons.AddMessage(DUN_AUTHENTICATOR_ADDON_TYPE, &addon); diff --git a/src/tests/kits/net/DialUpPreflet/PTPSettings.h b/src/tests/kits/net/DialUpPreflet/PTPSettings.h index 53fd02959a..c881a5a3c7 100644 --- a/src/tests/kits/net/DialUpPreflet/PTPSettings.h +++ b/src/tests/kits/net/DialUpPreflet/PTPSettings.h @@ -1,5 +1,5 @@ /* - * Copyright 2004, Waldemar Kornewald + * Copyright 2005, Waldemar Kornewald * Distributed under the terms of the MIT License. */ @@ -10,6 +10,9 @@ #include +class GeneralAddon; + + class PTPSettings { public: PTPSettings(); @@ -19,26 +22,20 @@ class PTPSettings { { return fAddons; } const BString& CurrentInterface() const { return fCurrent; } - - bool SetDefaultInterface(const char *name); - const char *DefaultInterface() const - { return fDefaultInterface; } - - bool GetPTPDirectories(BDirectory *settingsDirectory, - BDirectory *profileDirectory) const; + const char *SessionPassword() const; bool LoadSettings(const char *interfaceName, bool isNew); - void IsModified(bool *settings, bool *profile); - bool SaveSettings(BMessage *settings, BMessage *profile, bool saveTemporary); + void IsModified(bool *settings); + bool SaveSettings(BMessage *settings); bool SaveSettingsToFile(); - void LoadAddons(bool loadGeneralAddon = true); + void LoadAddons(); // must be called manually private: - BMessage fAddons, fSettings, fProfile; + BMessage fAddons, fSettings; BString fCurrent; - char *fDefaultInterface; + GeneralAddon *fGeneralAddon; }; diff --git a/src/tests/kits/net/DialUpPreflet/TODO b/src/tests/kits/net/DialUpPreflet/TODO index 56ad6a183e..cdc5288212 100644 --- a/src/tests/kits/net/DialUpPreflet/TODO +++ b/src/tests/kits/net/DialUpPreflet/TODO @@ -1,10 +1,12 @@ Short-term TODOs: - add "Revert Changes" button -- load add-ons from /boot/home/config/add-ons/ptp -- move DEVNOTES into a doxygen file and document the rest of the API - IPCP: check for incorrect settings (only IP addresses should be entered) - PPPoE: refresh interfaces list every second or so - ConnectionOptions: add field for entering number of connect retries and delay between retries +Mid-term TODOs: +- load add-ons from /boot/home/config/add-ons/ptp + Long-term TODOs: - (maybe) allow selecting multiple authenticators (in expert-mode) +- move DEVNOTES into a doxygen file and document the rest of the API diff --git a/src/tests/kits/net/DialUpPreflet/TextRequestDialog.cpp b/src/tests/kits/net/DialUpPreflet/TextRequestDialog.cpp index e4ed610348..fb225a620a 100644 --- a/src/tests/kits/net/DialUpPreflet/TextRequestDialog.cpp +++ b/src/tests/kits/net/DialUpPreflet/TextRequestDialog.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2004, Waldemar Kornewald + * Copyright 2004, Waldemar Kornewald * Distributed under the terms of the MIT License. */ diff --git a/src/tests/kits/net/DialUpPreflet/TextRequestDialog.h b/src/tests/kits/net/DialUpPreflet/TextRequestDialog.h index 35ba6bd9f1..c3ea9a424e 100644 --- a/src/tests/kits/net/DialUpPreflet/TextRequestDialog.h +++ b/src/tests/kits/net/DialUpPreflet/TextRequestDialog.h @@ -1,5 +1,5 @@ /* - * Copyright 2004, Waldemar Kornewald + * Copyright 2004, Waldemar Kornewald * Distributed under the terms of the MIT License. */