1 /* 2 * Copyright 2004, Waldemar Kornewald <Waldemar.Kornewald@web.de> 3 * Distributed under the terms of the MIT License. 4 */ 5 6 #include "PPPServer.h" 7 #include "SimpleMessageFilter.h" 8 #include <Application.h> 9 10 11 // the message constants that should be filtered 12 static const uint32 *kPPPWhatValues = { 13 // PPPS_CONNECT, 14 0 // end-of-list 15 }; 16 17 18 PPPServer::PPPServer() 19 : BHandler("PPPServer") 20 { 21 be_app->AddHandler(this); 22 fFilter = new SimpleMessageFilter(kPPPWhatValues, this); 23 be_app->AddCommonFilter(fFilter); 24 fListener = new PPPInterfaceListener(this); 25 fListener->WatchAllInterfaces(); 26 27 InitInterfaces(); 28 } 29 30 31 PPPServer::~PPPServer() 32 { 33 delete fListener; 34 be_app->RemoveCommonFilter(fFilter); 35 be_app->RemoveHandler(this); 36 delete fFilter; 37 } 38 39 40 void 41 PPPServer::MessageReceived(BMessage *message) 42 { 43 switch(message->what) { 44 case PPP_REPORT_MESSAGE: 45 HandleReportMessage(message); 46 break; 47 48 default: 49 BHandler::MessageReceived(message); 50 } 51 } 52 53 54 void 55 PPPServer::InitInterfaces() 56 { 57 } 58 59 60 bool 61 PPPServer::AskBeforeDialing(ppp_interface_id id) 62 { 63 return false; 64 } 65 66 67 void 68 PPPServer::HandleReportMessage(BMessage *message) 69 { 70 thread_id sender; 71 message->FindInt32("sender", &sender); 72 73 ppp_interface_id id; 74 if(message->FindInt32("interface", reinterpret_cast<int32*>(&id)) != B_OK) { 75 send_data(sender, B_OK, NULL, 0); 76 return; 77 } 78 79 int32 type, code; 80 message->FindInt32("type", &type); 81 message->FindInt32("code", &code); 82 83 if(type == PPP_MANAGER_REPORT && code == PPP_REPORT_INTERFACE_CREATED) { 84 // TODO: check if we need to add this interface to our watch-list 85 } else if(type == PPP_CONNECTION_REPORT) { 86 switch(code) { 87 case PPP_REPORT_GOING_UP: { 88 if(AskBeforeDialing(id)) { 89 OpenDialRequestWindow(id, sender); 90 return; 91 } 92 } break; 93 } 94 } else if(type == PPP_DESTRUCTION_REPORT) { 95 // TODO: check if this interface has DOD enabled. if so: create new! 96 } 97 98 send_data(sender, B_OK, NULL, 0); 99 } 100 101 102 void 103 PPPServer::OpenDialRequestWindow(ppp_interface_id id, thread_id sender) 104 { 105 106 } 107