From 9c15eafc5dc410f05867e757c469471ab81a4eab Mon Sep 17 00:00:00 2001 From: Waldemar Kornewald Date: Sun, 21 Nov 2004 12:46:41 +0000 Subject: [PATCH] Work in progress. Untested. All ppp_up instances are now maintained by KPPPManager. git-svn-id: file:///srv/svn/repos/haiku/trunk/current@10113 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/apps/bin/ppp_up/ConnectionView.cpp | 299 +++++++++++++++----- src/apps/bin/ppp_up/ConnectionView.h | 73 ++--- src/apps/bin/ppp_up/ConnectionWindow.cpp | 62 ++-- src/apps/bin/ppp_up/ConnectionWindow.h | 32 +-- src/apps/bin/ppp_up/Jamfile | 12 +- src/apps/bin/ppp_up/PPPDeskbarReplicant.cpp | 25 +- src/apps/bin/ppp_up/PPPDeskbarReplicant.h | 25 +- src/apps/bin/ppp_up/PPPUpApplication.cpp | 145 +++++++--- src/apps/bin/ppp_up/TODO | 7 +- src/apps/bin/ppp_up/ppp_up.rdef | 2 +- src/apps/bin/pppconfig/pppconfig.cpp | 25 +- 11 files changed, 434 insertions(+), 273 deletions(-) diff --git a/src/apps/bin/ppp_up/ConnectionView.cpp b/src/apps/bin/ppp_up/ConnectionView.cpp index 065f5b6440..3572c402b4 100644 --- a/src/apps/bin/ppp_up/ConnectionView.cpp +++ b/src/apps/bin/ppp_up/ConnectionView.cpp @@ -1,76 +1,134 @@ -/* ----------------------------------------------------------------------- - * Copyright (c) 2004 Waldemar Kornewald, Waldemar.Kornewald@web.de - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the "Software"), - * to deal in the Software without restriction, including without limitation - * the rights to use, copy, modify, merge, publish, distribute, sublicense, - * and/or sell copies of the Software, and to permit persons to whom the - * Software is furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER - * DEALINGS IN THE SOFTWARE. - * ----------------------------------------------------------------------- */ +/* + * 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() -static const char *kLabelConnect = "Connect"; -static const char *kLabelCancel = "Cancel"; +// GUI constants +static const uint32 kDefaultButtonWidth = 80; +// message constants static const uint32 kMsgCancel = 'CANC'; static const uint32 kMsgConnect = 'CONN'; -static const uint32 kDefaultButtonWidth = 80; +// 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"; + +// 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!"; -ConnectionView::ConnectionView(BRect rect, ppp_interface_id id, thread_id thread, - DialUpView *dun) +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), - fRequestThread(thread), - fDUNView(dun), - fConnecting(false) + fReportThread(thread), + fConnecting(false), + fKeepLabel(false), + fReplyRequested(true) { SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR)); BRect rect = Bounds(); rect.InsetBy(5, 5); - fAuthenticationView = dun->AuthenticationView(); - fAuthenticationView->RemoveSelf(); - fAuthenticationView->MoveTo(5, 5); - AddChild(fAuthenticationView); + 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"); + rect = authenticationBox->Bounds(); + rect.InsetBy(10, 5); + rect.top = 25; + BView *authenticationView = new BView(rect, "authenticationView", + B_FOLLOW_NONE, 0); + authenticationView->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR)); + rect = authenticationView->Bounds(); + 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); - rect.top = fAuthenticationView->Frame().bottom + 15; + // 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); + + authenticationView->AddChild(fUsername); + authenticationView->AddChild(fPassword); + authenticationView->AddChild(fSavePassword); + authenticationBox->AddChild(authenticationView); + 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; - fStatusView = dun->StatusView(); - fStatusView->RemoveSelf(); - fStatusView->MoveTo(5, rect.top); + rect.bottom = rect.top + 15; + fStatusView = new BStringView(rect, "StatusView", ""); AddChild(fStatusView); - rect.top = fStatusView->Frame().bottom + 10; + // 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, @@ -84,6 +142,13 @@ ConnectionView::ConnectionView(BRect rect, ppp_interface_id id, thread_id thread 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); } @@ -92,8 +157,10 @@ ConnectionView::AttachedToWindow() { fConnectButton->SetTarget(this); fCancelButton->SetTarget(this); + fSettings.LoadSettings(fInterfaceName.String(), false); - if(fDUNView->NeedsRequest() == false) + if(fAddon->CountAuthenticators() == 0 || fAddon->HasPassword()) + // TODO: || AskBeforeDialing == true Connect(); } @@ -102,12 +169,15 @@ void ConnectionView::MessageReceived(BMessage *message) { switch(message->what) { - case MSG_UPDATE: - Update(); - break; + 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_UP_FAILED: - UpFailed(); + case MSG_REPLY: + message->SendReply(B_OK); break; case kMsgConnect: @@ -124,55 +194,73 @@ ConnectionView::MessageReceived(BMessage *message) } +// update authentication UI void -ConnectionView::Update() +ConnectionView::Reload() { - fAttemptView->SetText(AttemptString().String()); -} - - -void -ConnectionView::UpFailed() -{ - Update(); - fConnectButton->SetEnabled(true); + 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; - fDUNView->SaveSettings(&settings, &profile, true); + fSettings.SaveSettings(&settings, &profile, true); driver_settings *temporaryProfile = MessageToDriverSettings(profile); - PPPInterface interface(fID); - interface.SetProfile(temporaryProfile); + PPPInterface *interface = new PPPInterface(PPPManager().CreateInterfaceWithName( + fInterfaceName.String())); + interface->SetProfile(temporaryProfile); free_driver_settings(temporaryProfile); fConnectButton->SetEnabled(false); fConnecting = true; - send_data(fRequestThread, B_OK, NULL, 0); + 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(fConnecting) { - // only disconnect if we are not connected yet - PPPInterface interface(fID); + 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); + interface->GetInterfaceInfo(&info); if(info.info.phase < PPP_ESTABLISHED_PHASE) { - interface.Down(); - be_app->PostMessage(B_QUIT_REQUESTED); - } - } else { - send_data(fRequestThread, B_ERROR, NULL, 0); - // tell requestor to cancel connection attempt - be_app->PostMessage(B_QUIT_REQUESTED); + thread_id down = spawn_thread(down_thread, "up_thread", B_NORMAL_PRIORITY, + interface); + resume_thread(down); + } else + delete interface; } } @@ -181,11 +269,9 @@ ConnectionView::Cancel() void ConnectionView::CleanUp() { - // give the "stolen" views back to make sure they are not deleted too early - fAuthenticationView->RemoveSelf(); - fDUNView->AddChild(fAuthenticationView); - fStatusView->RemoveSelf(); - fDUNView->AddChild(fStatusView); + // TODO: finish clean-up; (DONE?) + if(fReplyRequested) + Cancel(); } @@ -201,3 +287,68 @@ ConnectionView::AttemptString() const 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/apps/bin/ppp_up/ConnectionView.h b/src/apps/bin/ppp_up/ConnectionView.h index 34237035ec..efebd51c67 100644 --- a/src/apps/bin/ppp_up/ConnectionView.h +++ b/src/apps/bin/ppp_up/ConnectionView.h @@ -1,65 +1,68 @@ -/* ----------------------------------------------------------------------- - * Copyright (c) 2004 Waldemar Kornewald, Waldemar.Kornewald@web.de - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the "Software"), - * to deal in the Software without restriction, including without limitation - * the rights to use, copy, modify, merge, publish, distribute, sublicense, - * and/or sell copies of the Software, and to permit persons to whom the - * Software is furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER - * DEALINGS IN THE SOFTWARE. - * ----------------------------------------------------------------------- */ +/* + * Copyright 2004, Waldemar Kornewald + * Distributed under the terms of the MIT License. + */ #ifndef CONNECTION_VIEW__H #define CONNECTION_VIEW__H -#include "DialUpView.h" +#include +#include +#include "PPPUpAddon.h" +#include -#define MSG_UPDATE 'UPDT' - // sent when status changed -#define MSG_UP_FAILED 'UPFL' - // sent when up failed +#define MSG_UPDATE 'MUPD' +#define MSG_REPLY 'MRPY' class ConnectionView : public BView { friend class ConnectionWindow; public: - ConnectionView(BRect rect, ppp_interface_id id, thread_id thread, - DialUpView *view); + 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 Update(); - void UpFailed(); void Connect(); void Cancel(); void CleanUp(); BString AttemptString() const; + void UpdateStatus(int32 code); private: + PPPUpAddon *fAddon; + BString fInterfaceName; ppp_interface_id fID; - thread_id fRequestThread; - BView *fAuthenticationView, *fStatusView; - DialUpView *fDUNView; - BStringView *fAttemptView; + thread_id fReportThread; + BTextControl *fUsername, *fPassword; + BCheckBox *fSavePassword; + BStringView *fAttemptView, *fStatusView; BButton *fConnectButton, *fCancelButton; - bool fConnecting; + + bool fConnecting, fKeepLabel, fReplyRequested; + PTPSettings fSettings; }; diff --git a/src/apps/bin/ppp_up/ConnectionWindow.cpp b/src/apps/bin/ppp_up/ConnectionWindow.cpp index b4832da00f..223b914821 100644 --- a/src/apps/bin/ppp_up/ConnectionWindow.cpp +++ b/src/apps/bin/ppp_up/ConnectionWindow.cpp @@ -1,39 +1,23 @@ -/* ----------------------------------------------------------------------- - * Copyright (c) 2004 Waldemar Kornewald, Waldemar.Kornewald@web.de - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the "Software"), - * to deal in the Software without restriction, including without limitation - * the rights to use, copy, modify, merge, publish, distribute, sublicense, - * and/or sell copies of the Software, and to permit persons to whom the - * Software is furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER - * DEALINGS IN THE SOFTWARE. - * ----------------------------------------------------------------------- */ +/* + * Copyright 2004, Waldemar Kornewald + * Distributed under the terms of the MIT License. + */ #include "ConnectionWindow.h" +#include +#include -ConnectionWindow::ConnectionWindow(BRect frame, ppp_interface_id id, + +ConnectionWindow::ConnectionWindow(BRect frame, const char *name, ppp_interface_id id, thread_id replyThread) - : BWindow(frame, "Connecting...", B_MODAL_WINDOW, + : BWindow(frame, "", B_MODAL_WINDOW, B_NOT_RESIZABLE | B_NOT_ZOOMABLE) { - BRect bounds = Bounds(); - bounds.OffsetBy(bounds.Width() + 5, 0); - DialUpView *dun = new DialUpView(bounds); - fConnectionView = new ConnectionView(Bounds(), id, replyThread, dun); - - AddChild(dun); + BString title("Connecting to "); + title << "\"" << name << "\"..."; + SetTitle(title.String()); + fConnectionView = new ConnectionView(Bounds(), name, id, replyThread); AddChild(fConnectionView); } @@ -43,5 +27,25 @@ 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/apps/bin/ppp_up/ConnectionWindow.h b/src/apps/bin/ppp_up/ConnectionWindow.h index 7f870d9aa4..884e566fbb 100644 --- a/src/apps/bin/ppp_up/ConnectionWindow.h +++ b/src/apps/bin/ppp_up/ConnectionWindow.h @@ -1,24 +1,7 @@ -/* ----------------------------------------------------------------------- - * Copyright (c) 2004 Waldemar Kornewald, Waldemar.Kornewald@web.de - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the "Software"), - * to deal in the Software without restriction, including without limitation - * the rights to use, copy, modify, merge, publish, distribute, sublicense, - * and/or sell copies of the Software, and to permit persons to whom the - * Software is furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER - * DEALINGS IN THE SOFTWARE. - * ----------------------------------------------------------------------- */ +/* + * Copyright 2004, Waldemar Kornewald + * Distributed under the terms of the MIT License. + */ #ifndef CONNECTION_WINDOW__H #define CONNECTION_WINDOW__H @@ -29,9 +12,14 @@ class ConnectionWindow : public BWindow { public: - ConnectionWindow(BRect frame, ppp_interface_id id, thread_id replyThread); + 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; diff --git a/src/apps/bin/ppp_up/Jamfile b/src/apps/bin/ppp_up/Jamfile index 600c7eaa72..a4ba9d1489 100644 --- a/src/apps/bin/ppp_up/Jamfile +++ b/src/apps/bin/ppp_up/Jamfile @@ -10,7 +10,17 @@ AddResources ppp_up : ppp_up.rdef ; BinCommand ppp_up : ConnectionView.cpp ConnectionWindow.cpp + PPPUpAddon.cpp PPPUpApplication.cpp ; -LinkSharedOSLibs ppp_up : libdunview.a libppp.a be ; +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/apps/bin/ppp_up/PPPDeskbarReplicant.cpp b/src/apps/bin/ppp_up/PPPDeskbarReplicant.cpp index ada769ae1d..11ea375896 100644 --- a/src/apps/bin/ppp_up/PPPDeskbarReplicant.cpp +++ b/src/apps/bin/ppp_up/PPPDeskbarReplicant.cpp @@ -1,24 +1,7 @@ -/* ----------------------------------------------------------------------- - * Copyright (c) 2004 Waldemar Kornewald, Waldemar.Kornewald@web.de - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the "Software"), - * to deal in the Software without restriction, including without limitation - * the rights to use, copy, modify, merge, publish, distribute, sublicense, - * and/or sell copies of the Software, and to permit persons to whom the - * Software is furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER - * DEALINGS IN THE SOFTWARE. - * ----------------------------------------------------------------------- */ +/* + * Copyright 2004, Waldemar Kornewald + * Distributed under the terms of the MIT License. + */ #include "PPPDeskbarReplicant.h" #include "ConnectionWindow.h" diff --git a/src/apps/bin/ppp_up/PPPDeskbarReplicant.h b/src/apps/bin/ppp_up/PPPDeskbarReplicant.h index da15bafba4..b52bb44ae4 100644 --- a/src/apps/bin/ppp_up/PPPDeskbarReplicant.h +++ b/src/apps/bin/ppp_up/PPPDeskbarReplicant.h @@ -1,24 +1,7 @@ -/* ----------------------------------------------------------------------- - * Copyright (c) 2004 Waldemar Kornewald, Waldemar.Kornewald@web.de - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the "Software"), - * to deal in the Software without restriction, including without limitation - * the rights to use, copy, modify, merge, publish, distribute, sublicense, - * and/or sell copies of the Software, and to permit persons to whom the - * Software is furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER - * DEALINGS IN THE SOFTWARE. - * ----------------------------------------------------------------------- */ +/* + * Copyright 2004, Waldemar Kornewald + * Distributed under the terms of the MIT License. + */ #ifndef PPP_DESKBAR_REPLICANT__H #define PPP_DESKBAR_REPLICANT__H diff --git a/src/apps/bin/ppp_up/PPPUpApplication.cpp b/src/apps/bin/ppp_up/PPPUpApplication.cpp index d15f5eb3e8..3b060e146d 100644 --- a/src/apps/bin/ppp_up/PPPUpApplication.cpp +++ b/src/apps/bin/ppp_up/PPPUpApplication.cpp @@ -1,30 +1,15 @@ -/* ----------------------------------------------------------------------- - * Copyright (c) 2004 Waldemar Kornewald, Waldemar.Kornewald@web.de - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the "Software"), - * to deal in the Software without restriction, including without limitation - * the rights to use, copy, modify, merge, publish, distribute, sublicense, - * and/or sell copies of the Software, and to permit persons to whom the - * Software is furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER - * DEALINGS IN THE SOFTWARE. - * ----------------------------------------------------------------------- */ +/* + * Copyright 2004, Waldemar Kornewald + * Distributed under the terms of the MIT License. + */ #include #include #include "DialUpView.h" #include "ConnectionWindow.h" +#include +#include static const char *kSignature = "application/x-vnd.haiku.ppp_up"; @@ -32,6 +17,28 @@ static const char *kSignature = "application/x-vnd.haiku.ppp_up"; extern "C" _EXPORT BView *instantiate_deskbar_item(); +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; +}; + + BView* instantiate_deskbar_item() { @@ -44,29 +51,79 @@ static status_t report_thread(void *data) { - // TODO: add replicant when we finished connecting + 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) { + // TODO: + // 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)); + +// PPP_REPLY(sender, B_OK); + // TODO: remove this when finished with above + } else { + if(report.code == PPP_REPORT_UP_SUCCESSFUL) + ; // TODO: add deskbar replicant + + PPP_REPLY(sender, PPP_OK_DISABLE_REPORTS); + } + } return B_OK; } -class PPPUpApplication : public BApplication { - public: - PPPUpApplication(const char *name, ppp_interface_id id, - thread_id replyThread); - - virtual void ReadyToRun(); - - private: - const char *fName; - ppp_interface_id fID; - thread_id fReplyThread; - ConnectionWindow *fWindow; -}; - - int -main(const char *argv[], int argc) +main(int argc, const char *argv[]) { if(argc != 2) return -1; @@ -78,9 +135,7 @@ main(const char *argv[], int argc) receive_data(&replyThread, &id, sizeof(id)); new PPPUpApplication(name, id, replyThread); - be_app->Run(); - delete be_app; return 0; @@ -92,8 +147,7 @@ PPPUpApplication::PPPUpApplication(const char *name, ppp_interface_id id, : BApplication(kSignature), fName(name), fID(id), - fReplyThread(replyThread), - fWindow(NULL) + fReplyThread(replyThread) { } @@ -101,6 +155,9 @@ PPPUpApplication::PPPUpApplication(const char *name, ppp_interface_id id, void PPPUpApplication::ReadyToRun() { - // TODO: create report message thread (which in turn sends the reply) - // TODO: create connection window + // 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/apps/bin/ppp_up/TODO b/src/apps/bin/ppp_up/TODO index 522121e984..565ea98c80 100644 --- a/src/apps/bin/ppp_up/TODO +++ b/src/apps/bin/ppp_up/TODO @@ -1,7 +1,6 @@ -If has temporary profile: -Open connection window and request password. - 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. -What if preflet changes profile while connecting? +Add some indicator to the add-ons message that says we are ppp_up, not the preflet. diff --git a/src/apps/bin/ppp_up/ppp_up.rdef b/src/apps/bin/ppp_up/ppp_up.rdef index ce61210d37..61654e33c8 100644 --- a/src/apps/bin/ppp_up/ppp_up.rdef +++ b/src/apps/bin/ppp_up/ppp_up.rdef @@ -1,5 +1,5 @@ /* - pppinit.rdef + ppp_up.rdef */ resource app_signature "application/x-vnd.haiku.ppp_up"; diff --git a/src/apps/bin/pppconfig/pppconfig.cpp b/src/apps/bin/pppconfig/pppconfig.cpp index 21c46ad349..1e55e32f77 100644 --- a/src/apps/bin/pppconfig/pppconfig.cpp +++ b/src/apps/bin/pppconfig/pppconfig.cpp @@ -1,24 +1,7 @@ -/* ----------------------------------------------------------------------- - * Copyright (c) 2003-2004 Waldemar Kornewald, Waldemar.Kornewald@web.de - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the "Software"), - * to deal in the Software without restriction, including without limitation - * the rights to use, copy, modify, merge, publish, distribute, sublicense, - * and/or sell copies of the Software, and to permit persons to whom the - * Software is furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER - * DEALINGS IN THE SOFTWARE. - * ----------------------------------------------------------------------- */ +/* + * Copyright 2003-2004, Waldemar Kornewald + * Distributed under the terms of the MIT License. + */ #include #include