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