160abfca0SWaldemar Kornewald //----------------------------------------------------------------------- 260abfca0SWaldemar Kornewald // This software is part of the OpenBeOS distribution and is covered 360abfca0SWaldemar Kornewald // by the OpenBeOS license. 460abfca0SWaldemar Kornewald // 560abfca0SWaldemar Kornewald // Copyright (c) 2004 Waldemar Kornewald, Waldemar.Kornewald@web.de 660abfca0SWaldemar Kornewald //----------------------------------------------------------------------- 760abfca0SWaldemar Kornewald 860abfca0SWaldemar Kornewald #include "PPPServer.h" 960abfca0SWaldemar Kornewald #include "SimpleMessageFilter.h" 1060abfca0SWaldemar Kornewald #include <Application.h> 1160abfca0SWaldemar Kornewald 1260abfca0SWaldemar Kornewald 1360abfca0SWaldemar Kornewald // the message constants that should be filtered 1460abfca0SWaldemar Kornewald static const uint32 *kPPPWhatValues = { 1560abfca0SWaldemar Kornewald // PPPS_CONNECT, 1660abfca0SWaldemar Kornewald 0 // end-of-list 1760abfca0SWaldemar Kornewald }; 1860abfca0SWaldemar Kornewald 1960abfca0SWaldemar Kornewald 2060abfca0SWaldemar Kornewald PPPServer::PPPServer() 2160abfca0SWaldemar Kornewald : BHandler("PPPServer") 2260abfca0SWaldemar Kornewald { 2360abfca0SWaldemar Kornewald be_app->AddHandler(this); 2460abfca0SWaldemar Kornewald fFilter = new SimpleMessageFilter(kPPPWhatValues, this); 2560abfca0SWaldemar Kornewald be_app->AddCommonFilter(fFilter); 26*0a628cf2SWaldemar Kornewald fListener = new PPPInterfaceListener(this); 27*0a628cf2SWaldemar Kornewald fListener->WatchAllInterfaces(); 28*0a628cf2SWaldemar Kornewald 29*0a628cf2SWaldemar Kornewald InitInterfaces(); 3060abfca0SWaldemar Kornewald } 3160abfca0SWaldemar Kornewald 3260abfca0SWaldemar Kornewald 3360abfca0SWaldemar Kornewald PPPServer::~PPPServer() 3460abfca0SWaldemar Kornewald { 35*0a628cf2SWaldemar Kornewald delete fListener; 3660abfca0SWaldemar Kornewald be_app->RemoveCommonFilter(fFilter); 37*0a628cf2SWaldemar Kornewald be_app->RemoveHandler(this); 3860abfca0SWaldemar Kornewald delete fFilter; 3960abfca0SWaldemar Kornewald } 4060abfca0SWaldemar Kornewald 4160abfca0SWaldemar Kornewald 4260abfca0SWaldemar Kornewald void 4360abfca0SWaldemar Kornewald PPPServer::MessageReceived(BMessage *message) 4460abfca0SWaldemar Kornewald { 4560abfca0SWaldemar Kornewald switch(message->what) { 46*0a628cf2SWaldemar Kornewald case PPP_REPORT_MESSAGE: 47*0a628cf2SWaldemar Kornewald HandleReportMessage(message); 48*0a628cf2SWaldemar Kornewald break; 4960abfca0SWaldemar Kornewald 50*0a628cf2SWaldemar Kornewald // TODO: handle 5160abfca0SWaldemar Kornewald 5260abfca0SWaldemar Kornewald default: 5360abfca0SWaldemar Kornewald BHandler::MessageReceived(message); 5460abfca0SWaldemar Kornewald } 5560abfca0SWaldemar Kornewald } 56*0a628cf2SWaldemar Kornewald 57*0a628cf2SWaldemar Kornewald 58*0a628cf2SWaldemar Kornewald void 59*0a628cf2SWaldemar Kornewald PPPServer::InitInterfaces() 60*0a628cf2SWaldemar Kornewald { 61*0a628cf2SWaldemar Kornewald } 62*0a628cf2SWaldemar Kornewald 63*0a628cf2SWaldemar Kornewald 64*0a628cf2SWaldemar Kornewald bool 65*0a628cf2SWaldemar Kornewald PPPServer::AskBeforeDialing(ppp_interface_id id) 66*0a628cf2SWaldemar Kornewald { 67*0a628cf2SWaldemar Kornewald return false; 68*0a628cf2SWaldemar Kornewald } 69*0a628cf2SWaldemar Kornewald 70*0a628cf2SWaldemar Kornewald 71*0a628cf2SWaldemar Kornewald void 72*0a628cf2SWaldemar Kornewald PPPServer::HandleReportMessage(BMessage *message) 73*0a628cf2SWaldemar Kornewald { 74*0a628cf2SWaldemar Kornewald thread_id sender; 75*0a628cf2SWaldemar Kornewald message->FindInt32("sender", &sender); 76*0a628cf2SWaldemar Kornewald 77*0a628cf2SWaldemar Kornewald ppp_interface_id id; 78*0a628cf2SWaldemar Kornewald if(message->FindInt32("interface", reinterpret_cast<int32*>(&id)) != B_OK) { 79*0a628cf2SWaldemar Kornewald send_data(sender, B_OK, NULL, 0); 80*0a628cf2SWaldemar Kornewald return; 81*0a628cf2SWaldemar Kornewald } 82*0a628cf2SWaldemar Kornewald 83*0a628cf2SWaldemar Kornewald int32 type, code; 84*0a628cf2SWaldemar Kornewald message->FindInt32("type", &type); 85*0a628cf2SWaldemar Kornewald message->FindInt32("code", &code); 86*0a628cf2SWaldemar Kornewald 87*0a628cf2SWaldemar Kornewald if(type == PPP_MANAGER_REPORT && code == PPP_REPORT_INTERFACE_CREATED) { 88*0a628cf2SWaldemar Kornewald // TODO: check if we need to add this interface to our watch-list 89*0a628cf2SWaldemar Kornewald } else if(type == PPP_CONNECTION_REPORT) { 90*0a628cf2SWaldemar Kornewald switch(code) { 91*0a628cf2SWaldemar Kornewald case PPP_REPORT_GOING_UP: { 92*0a628cf2SWaldemar Kornewald if(AskBeforeDialing(id)) { 93*0a628cf2SWaldemar Kornewald // OpenDialRequestWindow(id, sender); 94*0a628cf2SWaldemar Kornewald return; 95*0a628cf2SWaldemar Kornewald } 96*0a628cf2SWaldemar Kornewald } break; 97*0a628cf2SWaldemar Kornewald } 98*0a628cf2SWaldemar Kornewald } else if(type == PPP_DESTRUCTION_REPORT) { 99*0a628cf2SWaldemar Kornewald // TODO: check if this interface has DOD enabled. if so: create new! 100*0a628cf2SWaldemar Kornewald } 101*0a628cf2SWaldemar Kornewald 102*0a628cf2SWaldemar Kornewald send_data(sender, B_OK, NULL, 0); 103*0a628cf2SWaldemar Kornewald } 104