bool PPPoEAddon::LoadSettings(BMessage *settings, BMessage *profile, bool isNew) { fIsNew = isNew; fInterfaceName = fServiceName = ""; fSettings = settings; fProfile = profile; if(fPPPoEView) fPPPoEView->Reload(); if(!settings || !profile || isNew) return true; BMessage device; int32 deviceIndex = 0; if(!FindMessageParameter(PPP_DEVICE_KEY, *fSettings, &device, &deviceIndex)) return false; // error: no device BString name; if(device.FindString(MDSU_VALUES, &name) != B_OK || name != kKernelModuleName) return false; // error: no device BMessage parameter; int32 index = 0; if(!FindMessageParameter(PPPoE_INTERFACE_KEY, device, ¶meter, &index) || parameter.FindString(MDSU_VALUES, &fInterfaceName) != B_OK) return false; // error: no interface else { parameter.AddBool(MDSU_VALID, true); device.ReplaceMessage(MDSU_PARAMETERS, index, ¶meter); } index = 0; if(!FindMessageParameter(PPPoE_SERVICE_NAME_KEY, device, ¶meter, &index) || parameter.FindString(MDSU_VALUES, &fServiceName) != B_OK) fServiceName = ""; else { parameter.AddBool(MDSU_VALID, true); device.ReplaceMessage(MDSU_PARAMETERS, index, ¶meter); } device.AddBool(MDSU_VALID, true); fSettings->ReplaceMessage(MDSU_PARAMETERS, deviceIndex, &device); if(fPPPoEView) fPPPoEView->Reload(); return true; }
bool ConnectionOptionsAddon::LoadSettings(BMessage *settings, BMessage *profile, bool isNew) { fIsNew = isNew; fDoesDialOnDemand = fAskBeforeDialing = fDoesAutoRedial = false; fSettings = settings; fProfile = profile; if(fConnectionOptionsView) fConnectionOptionsView->Reload(); // reset all views (empty settings) if(!settings || !profile || isNew) return true; BMessage parameter; int32 index = 0; const char *value; if(FindMessageParameter(PPP_DIAL_ON_DEMAND_KEY, *fSettings, ¶meter, &index) && parameter.FindString(MDSU_VALUES, &value) == B_OK) { if(get_boolean_value(value, false)) fDoesDialOnDemand = true; parameter.AddBool(MDSU_VALID, true); fSettings->ReplaceMessage(MDSU_PARAMETERS, index, ¶meter); } index = 0; if(FindMessageParameter(PPP_ASK_BEFORE_DIALING_KEY, *fSettings, ¶meter, &index) && parameter.FindString(MDSU_VALUES, &value) == B_OK) { if(get_boolean_value(value, false)) fAskBeforeDialing = true; parameter.AddBool(MDSU_VALID, true); fSettings->ReplaceMessage(MDSU_PARAMETERS, index, ¶meter); } index = 0; if(FindMessageParameter(PPP_AUTO_REDIAL_KEY, *fSettings, ¶meter, &index) && parameter.FindString(MDSU_VALUES, &value) == B_OK) { if(get_boolean_value(value, false)) fDoesAutoRedial = true; parameter.AddBool(MDSU_VALID, true); fSettings->ReplaceMessage(MDSU_PARAMETERS, index, ¶meter); } if(fConnectionOptionsView) fConnectionOptionsView->Reload(); // reload new settings return true; }
int32 IPCPAddon::FindIPCPProtocol(const BMessage& message, BMessage *protocol) const { if(!protocol) return -1; BString name; for(int32 index = 0; FindMessageParameter(PPP_PROTOCOL_KEY, message, protocol, &index); index++) if(protocol->FindString(MDSU_VALUES, &name) == B_OK && name == kKernelModuleName) return index; return -1; }
bool IPCPAddon::LoadSettings(BMessage *settings, BMessage *profile, bool isNew) { fIsNew = isNew; fIsEnabled = false; fIPAddress = fPrimaryDNS = fSecondaryDNS = ""; fSettings = settings; fProfile = profile; if(fIPCPView) fIPCPView->Reload(); // reset all views (empty settings) if(!settings || !profile || isNew) return true; BMessage protocol; // settings int32 protocolIndex = FindIPCPProtocol(*fSettings, &protocol); if(protocolIndex < 0) return true; 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 BMessage local; int32 localSideIndex = 0; if(!FindMessageParameter(IPCP_LOCAL_SIDE_KEY, protocol, &local, &localSideIndex)) local.MakeEmpty(); // just fall through and pretend we have an empty "Local" side parameter // now load the supported parameters (the client-relevant subset) BString name; BMessage parameter; int32 index = 0; if(!FindMessageParameter(IPCP_IP_ADDRESS_KEY, local, ¶meter, &index) || parameter.FindString(MDSU_VALUES, &fIPAddress) != B_OK) fIPAddress = ""; else { if(fIPAddress == "auto") fIPAddress = ""; parameter.AddBool(MDSU_VALID, true); local.ReplaceMessage(MDSU_PARAMETERS, index, ¶meter); } index = 0; if(!FindMessageParameter(IPCP_PRIMARY_DNS_KEY, local, ¶meter, &index) || parameter.FindString(MDSU_VALUES, &fPrimaryDNS) != B_OK) fPrimaryDNS = ""; else { if(fPrimaryDNS == "auto") fPrimaryDNS = ""; parameter.AddBool(MDSU_VALID, true); local.ReplaceMessage(MDSU_PARAMETERS, index, ¶meter); } index = 0; if(!FindMessageParameter(IPCP_SECONDARY_DNS_KEY, local, ¶meter, &index) || parameter.FindString(MDSU_VALUES, &fSecondaryDNS) != B_OK) fSecondaryDNS = ""; else { if(fSecondaryDNS == "auto") fSecondaryDNS = ""; parameter.AddBool(MDSU_VALID, true); local.ReplaceMessage(MDSU_PARAMETERS, index, ¶meter); } local.AddBool(MDSU_VALID, true); protocol.ReplaceMessage(MDSU_PARAMETERS, localSideIndex, &local); protocol.AddBool(MDSU_VALID, true); fProfile->ReplaceMessage(MDSU_PARAMETERS, protocolIndex, &protocol); if(fIPCPView) fIPCPView->Reload(); return true; }