Logo Search packages:      
Sourcecode: kdeadmin-kde4 version File versions  Download package

KNetworkInterface * KNetworkConfigParser::getInterfaceInfo ( QDomElement  interface,
const QString &  type 
) [protected, virtual]

Parses all of the <interface>...</interface> entries in the xml configuration file.

Parses all of the <interface>...</interface> entries in the xml configuration file. Returns a KNetworkInterface object with all the info of the interface.

Definition at line 591 of file knetworkconfigparser.cpp.

References KNetworkInterface::getBootProto(), KNetworkInterface::getDeviceName(), KNetworkInterface::getIpAddress(), KNetworkInterface::getType(), KNetworkInterface::isActive(), KNetworkInterface::setActive(), KNetworkInterface::setBootProto(), KNetworkInterface::setBroadcast(), KNetworkInterface::setDescription(), KNetworkInterface::setDeviceName(), KNetworkInterface::setIpAddress(), KNetworkInterface::setMacAddress(), KNetworkInterface::setNetmask(), KNetworkInterface::setNetwork(), KNetworkInterface::setOnBoot(), and KNetworkInterface::setType().

Referenced by getWirelessInterfaceInfo(), and readListIfacesSlot().

                                                                                                    {
  QDomNode node = interface.firstChild();
  KNetworkInterface *tempDevice = new KNetworkInterface();
  //tempDevice->setDescription(i18n("Ethernet Network Device"));

  while ( !node.isNull() )
  {
    if ( node.isElement() )
    {
      QString nodeName =node.nodeName();

      //Parsing --get interfaces configuration
      if ( node.isElement() && node.nodeName() == "configuration" )
      {
        QDomNode configNode = node.firstChild();
        while ( !configNode.isNull() )
        {
          if ( configNode.isElement() )
          {
            QString configNodeName =configNode.nodeName();

            if ( configNodeName == "auto" )
            {
              QDomElement e = configNode.toElement();
              if (e.text() == "1")
                tempDevice->setOnBoot("yes");
              else
                tempDevice->setOnBoot("no");
            }
            else if ( configNodeName == "bootproto" )
            {
              QDomElement e = configNode.toElement();
              tempDevice->setBootProto(e.text());
            }
            if ( configNodeName == "address" || configNodeName == "addr")
            {
              QDomElement e = configNode.toElement();
              if (!e.text().isEmpty())
                    tempDevice->setIpAddress(e.text());
            }
            else if ( configNodeName == "netmask" || configNodeName == "mask")
            {
              QDomElement e = configNode.toElement();
              if (!e.text().isEmpty())
                    tempDevice->setNetmask(e.text());
            }
            else if ( configNodeName == "network" )
            {
              QDomElement e = configNode.toElement();
              if (!e.text().isEmpty())
                tempDevice->setNetwork(e.text());
            }
            else if ( configNodeName == "broadcast" || configNodeName == "bdcast")
            {
              QDomElement e = configNode.toElement();
              if (!e.text().isEmpty())
                    tempDevice->setBroadcast(e.text());
            }
            configNode = configNode.nextSibling();
          }
        }
      }

      //Parse -d list_ifaces interfaces configuration
      if ( nodeName == "addr")
      {
        QDomElement e = node.toElement();
        if (!e.text().isEmpty())
             tempDevice->setIpAddress(e.text());
      }
      else if ( nodeName == "mask")
      {
        QDomElement e = node.toElement();
        if (!e.text().isEmpty())
          tempDevice->setNetmask(e.text());
      }
      else if ( nodeName == "bdcast")
      {
        QDomElement e = node.toElement();
        if (!e.text().isEmpty())
              tempDevice->setBroadcast(e.text());
      }


      //These ones are common for both --get and -d list_ifaces
      else if ( nodeName == "dev" )
      {
        QDomElement e = node.toElement();
        tempDevice->setDeviceName(e.text());
      }
      //we had to add the OR because the xml sintax when listing the interfaces
      //is different than when loading the network info. ie.: enabled->active
      //address->addr, etc...
      else if ( nodeName == "enabled"  || nodeName == "active")
      {
        QDomElement e = node.toElement();
        if (e.text() == "1")
          tempDevice->setActive(true);
        else
          tempDevice->setActive(false);
      }
      else if ( nodeName == "hwaddr" )
      {
        QDomElement e = node.toElement();
        if (!e.text().isEmpty())
          tempDevice->setMacAddress(e.text());
      }
    }
    node = node.nextSibling();
  }
  if (type != QString())
    tempDevice->setType(type);

  QString description;
  KConfig _cfg( "knetworkconfrc", KConfig::SimpleConfig );
  KConfigGroup cfg(&_cfg, "Interfaces");
  description = cfg.readEntry(tempDevice->getDeviceName(),QString());
  if (!description.isEmpty())
    tempDevice->setDescription(description);
  else
  {
    if (tempDevice->getType() == ETHERNET_IFACE_TYPE)
      tempDevice->setDescription(i18n("Ethernet Network Device"));
    else if (tempDevice->getType() == WIRELESS_IFACE_TYPE)
      tempDevice->setDescription(i18n("Wireless Network Device"));
  }

  //If the backend reports that the interface is up (even if it isn't true),
  //and the interface doesn't have an IP address assgined it means that effectively
  //the interface is down and should be marked as inactive.
  if (tempDevice->isActive() && tempDevice->getIpAddress().isEmpty())
    tempDevice->setActive(false);

  //Clear IP address settings if boot protocol is dhcp or bootp, in case that they are
  //set in the config files.
  if ((tempDevice->getBootProto().toLower() == "dhcp") || (tempDevice->getBootProto().toLower() == "bootp"))
  {
    tempDevice->setIpAddress("");
    tempDevice->setNetmask("");
    tempDevice->setNetwork("");
    tempDevice->setBroadcast("");
  }

  return tempDevice;
}


Generated by  Doxygen 1.6.0   Back to index